]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-unit-util: define helper for ManagedOOMMemoryPressureLimit=
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 18 Jun 2025 13:24:34 +0000 (15:24 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 3 Jul 2025 08:37:33 +0000 (10:37 +0200)
src/shared/bus-unit-util.c

index f99ced824f3173a98c8a4e1b1e2ac4b1735f9c9d..d08d1585a2aa05f052422fe41c5b740608034cab 100644 (file)
@@ -268,6 +268,21 @@ static int bus_append_parse_size(sd_bus_message *m, const char *field, const cha
         return 1;
 }
 
+static int bus_append_parse_permyriad(sd_bus_message *m, const char *field, const char *eq) {
+        int r;
+
+        r = parse_permyriad(eq);
+        if (r < 0)
+                return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
+
+        /* Pass around scaled to 2^32-1 == 100% */
+        r = sd_bus_message_append(m, "(sv)", field, "u", UINT32_SCALE_FROM_PERMYRIAD(r));
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        return 1;
+}
+
 static int bus_append_exec_command(sd_bus_message *m, const char *field, const char *eq) {
         bool explicit_path = false, done = false, ambient_hack = false;
         _cleanup_strv_free_ char **l = NULL, **ex_opts = NULL;
@@ -582,18 +597,8 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
                               "DelegateSubgroup"))
                 return bus_append_string(m, field, eq);
 
-        if (STR_IN_SET(field, "ManagedOOMMemoryPressureLimit")) {
-                r = parse_permyriad(eq);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
-
-                /* Pass around scaled to 2^32-1 == 100% */
-                r = sd_bus_message_append(m, "(sv)", field, "u", UINT32_SCALE_FROM_PERMYRIAD(r));
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                return 1;
-        }
+        if (STR_IN_SET(field, "ManagedOOMMemoryPressureLimit"))
+                return bus_append_parse_permyriad(m, field, eq);
 
         if (STR_IN_SET(field, "MemoryAccounting",
                               "MemoryZSwapWriteback",