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