summaryrefslogtreecommitdiff
path: root/src/shared/bus-util.c
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2015-10-12 05:16:05 +0000
committerEvgeny Vereshchagin <evvers@ya.ru>2015-10-12 05:16:05 +0000
commitc9d031c353177420809b2e187f0392ad9ba8362a (patch)
tree210788d26956d756761625cd6e3d479abd414b76 /src/shared/bus-util.c
parent0a41d91f3022ae5107151ebd1af9b65a55030c7e (diff)
bus-util: add bus_property_get_rlimit (move from core/dbus_execute)
Diffstat (limited to 'src/shared/bus-util.c')
-rw-r--r--src/shared/bus-util.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 52ec7eee7f..57bc6d987d 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -2138,3 +2138,42 @@ bool is_kdbus_available(void) {
return ioctl(fd, KDBUS_CMD_BUS_MAKE, &cmd) >= 0;
}
+
+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) {
+
+ struct rlimit *rl;
+ uint64_t u;
+ rlim_t x;
+
+ assert(bus);
+ assert(reply);
+ assert(userdata);
+
+ rl = *(struct rlimit**) userdata;
+ if (rl)
+ x = rl->rlim_max;
+ else {
+ struct rlimit buf = {};
+ int z;
+
+ z = rlimit_from_string(property);
+ assert(z >= 0);
+
+ getrlimit(z, &buf);
+ x = buf.rlim_max;
+ }
+
+ /* rlim_t might have different sizes, let's map
+ * RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on
+ * all archs */
+ u = x == RLIM_INFINITY ? (uint64_t) -1 : (uint64_t) x;
+
+ return sd_bus_message_append(reply, "t", u);
+}