anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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