valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0487-core-manager-expose-DefaultLimit-as-properties-on-db.patch

a19bc6
From 86669b5615683a5292ca048c362a000d471329d9 Mon Sep 17 00:00:00 2001
a19bc6
From: Evgeny Vereshchagin <evvers@ya.ru>
a19bc6
Date: Mon, 12 Oct 2015 06:39:00 +0000
a19bc6
Subject: [PATCH] core: manager: expose DefaultLimit* as properties on dbus
a19bc6
a19bc6
(cherry picked from commit 97eb42315785821dae3349978a1adf7d49aa5fc1)
a19bc6
a19bc6
Conflicts:
a19bc6
	src/core/dbus-manager.c
a19bc6
a19bc6
Resolves: #1427927
a19bc6
---
23b3cf
 src/core/dbus-manager.c          | 16 +++++++++++++
23b3cf
 src/libsystemd/sd-bus/bus-util.c | 39 ++++++++++++++++++++++++++++++++
a19bc6
 src/libsystemd/sd-bus/bus-util.h |  1 +
a19bc6
 3 files changed, 56 insertions(+)
a19bc6
a19bc6
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
Pablo Greco 48fc63
index 9d4f633774..d34ed042f6 100644
a19bc6
--- a/src/core/dbus-manager.c
a19bc6
+++ b/src/core/dbus-manager.c
a19bc6
@@ -2049,6 +2049,22 @@ const sd_bus_vtable bus_manager_vtable[] = {
a19bc6
         SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
         SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
         SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
+        SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
         SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL, offsetof(Manager, default_tasks_max), SD_BUS_VTABLE_PROPERTY_CONST),
a19bc6
 
a19bc6
         SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED),
a19bc6
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
Pablo Greco 48fc63
index f46fa2bbf3..2634574279 100644
a19bc6
--- a/src/libsystemd/sd-bus/bus-util.c
a19bc6
+++ b/src/libsystemd/sd-bus/bus-util.c
a19bc6
@@ -1937,3 +1937,42 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un
a19bc6
 
a19bc6
         return 0;
a19bc6
 }
a19bc6
+
a19bc6
+int bus_property_get_rlimit(
a19bc6
+                sd_bus *bus,
a19bc6
+                const char *path,
a19bc6
+                const char *interface,
a19bc6
+                const char *property,
a19bc6
+                sd_bus_message *reply,
a19bc6
+                void *userdata,
a19bc6
+                sd_bus_error *error) {
a19bc6
+
a19bc6
+        struct rlimit *rl;
a19bc6
+        uint64_t u;
a19bc6
+        rlim_t x;
a19bc6
+
a19bc6
+        assert(bus);
a19bc6
+        assert(reply);
a19bc6
+        assert(userdata);
a19bc6
+
a19bc6
+        rl = *(struct rlimit**) userdata;
a19bc6
+        if (rl)
a19bc6
+                x = rl->rlim_max;
a19bc6
+        else {
a19bc6
+                struct rlimit buf = {};
a19bc6
+                int z;
a19bc6
+
a19bc6
+                z = rlimit_from_string(startswith(property, "Default") ? property + 7 : property);
a19bc6
+                assert(z >= 0);
a19bc6
+
a19bc6
+                getrlimit(z, &buf;;
a19bc6
+                x = buf.rlim_max;
a19bc6
+        }
a19bc6
+
a19bc6
+        /* rlim_t might have different sizes, let's map
a19bc6
+         * RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on
a19bc6
+         * all archs */
a19bc6
+        u = x == RLIM_INFINITY ? (uint64_t) -1 : (uint64_t) x;
a19bc6
+
a19bc6
+        return sd_bus_message_append(reply, "t", u);
a19bc6
+}
a19bc6
diff --git a/src/libsystemd/sd-bus/bus-util.h b/src/libsystemd/sd-bus/bus-util.h
Pablo Greco 48fc63
index 8c8846c6ee..d5f4e9750d 100644
a19bc6
--- a/src/libsystemd/sd-bus/bus-util.h
a19bc6
+++ b/src/libsystemd/sd-bus/bus-util.h
a19bc6
@@ -214,3 +214,4 @@ int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet);
a19bc6
 DEFINE_TRIVIAL_CLEANUP_FUNC(BusWaitForJobs*, bus_wait_for_jobs_free);
a19bc6
 
a19bc6
 int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes);
a19bc6
+int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);