chiark / gitweb /
core: expose soft limits on the bus
authorEvgeny Vereshchagin <evvers@ya.ru>
Sat, 28 Nov 2015 16:49:13 +0000 (16:49 +0000)
committerSven Eden <yamakuzure@gmx.net>
Wed, 17 May 2017 13:22:14 +0000 (15:22 +0200)
This is a follow-up for https://github.com/elogind/elogind/pull/1994

See https://github.com/elogind/elogind/pull/1994#issuecomment-160087219

src/shared/bus-util.c

index eee8fca1416fd80f10cd879d1697f230373a30c3..4b0337b34a44f0e5f504642b36b6c454b3b65c56 100644 (file)
@@ -2380,23 +2380,28 @@ int bus_property_get_rlimit(
         struct rlimit *rl;
         uint64_t u;
         rlim_t x;
         struct rlimit *rl;
         uint64_t u;
         rlim_t x;
+        const char *is_soft;
 
         assert(bus);
         assert(reply);
         assert(userdata);
 
 
         assert(bus);
         assert(reply);
         assert(userdata);
 
+        is_soft = endswith(property, "Soft");
         rl = *(struct rlimit**) userdata;
         if (rl)
         rl = *(struct rlimit**) userdata;
         if (rl)
-                x = rl->rlim_max;
+                x = is_soft ? rl->rlim_cur : rl->rlim_max;
         else {
                 struct rlimit buf = {};
                 int z;
         else {
                 struct rlimit buf = {};
                 int z;
+                const char *s;
+
+                s = is_soft ? strndupa(property, is_soft - property) : property;
 
 
-                z = rlimit_from_string(strstr(property, "Limit"));
+                z = rlimit_from_string(strstr(s, "Limit"));
                 assert(z >= 0);
 
                 getrlimit(z, &buf);
                 assert(z >= 0);
 
                 getrlimit(z, &buf);
-                x = buf.rlim_max;
+                x = is_soft ? buf.rlim_cur : buf.rlim_max;
         }
 
         /* rlim_t might have different sizes, let's map
         }
 
         /* rlim_t might have different sizes, let's map