]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-unit-util: define helper for DeviceAllow=
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 18 Jun 2025 14:17:50 +0000 (16:17 +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 611d8a185837a845c840ddf2ab490085d4a3b48b..1eb3fa30d4a38bf559a7cd7d89eaf1ef2b5cb517 100644 (file)
@@ -376,6 +376,28 @@ static int bus_append_parse_cpu_quota(sd_bus_message *m, const char *field, cons
         return 1;
 }
 
+static int bus_append_parse_device_allow(sd_bus_message *m, const char *field, const char *eq) {
+        int r;
+
+        if (isempty(eq))
+                r = sd_bus_message_append(m, "(sv)", field, "a(ss)", 0);
+        else {
+                const char *path = eq, *rwm = NULL, *e;
+
+                e = strchr(eq, ' ');
+                if (e) {
+                        path = strndupa_safe(eq, e - eq);
+                        rwm = e + 1;
+                }
+
+                r = sd_bus_message_append(m, "(sv)", field, "a(ss)", 1, path, strempty(rwm));
+        }
+        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;
@@ -738,26 +760,9 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
         if (streq(field, "CPUQuotaPeriodSec"))
                 return bus_append_parse_sec_rename(m, field, isempty(eq) ? "infinity" : eq);
 
-        if (streq(field, "DeviceAllow")) {
-                if (isempty(eq))
-                        r = sd_bus_message_append(m, "(sv)", field, "a(ss)", 0);
-                else {
-                        const char *path = eq, *rwm = NULL, *e;
-
-                        e = strchr(eq, ' ');
-                        if (e) {
-                                path = strndupa_safe(eq, e - eq);
-                                rwm = e+1;
-                        }
-
-                        r = sd_bus_message_append(m, "(sv)", field, "a(ss)", 1, path, strempty(rwm));
-                }
+        if (streq(field, "DeviceAllow"))
+                return bus_append_parse_device_allow(m, field, eq);
 
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                return 1;
-        }
 
         if (cgroup_io_limit_type_from_string(field) >= 0) {