diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-13 17:28:29 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-13 17:28:29 +0200 |
commit | 400c32ef24bb62915359bc0d5688fd14fda5153d (patch) | |
tree | ef7c9239381fc1200e3c9ac6af52e5631f8e7e9e /src/shared/bus-util.c | |
parent | 18438f262c60823ad01bf88b7a8a326c3e8b511d (diff) | |
parent | 97eb42315785821dae3349978a1adf7d49aa5fc1 (diff) |
Merge pull request #1534 from evverx/expose-rlimits-on-dbus
Expose `DefaultLimit*` as properties on dbus
Diffstat (limited to 'src/shared/bus-util.c')
-rw-r--r-- | src/shared/bus-util.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 52ec7eee7f..36a29fbdc0 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(startswith(property, "Default") ? property + 7 : 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); +} |