]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-unit-util: define helper for RootImageOptions=
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Jun 2025 12:21:43 +0000 (14:21 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 3 Jul 2025 17:35:33 +0000 (19:35 +0200)
src/shared/bus-unit-util.c

index a8925c1a002cc08ad87bcc579833320e76215ae3..9d22a60d344a8483948c7264aa070b93fad487ad 100644 (file)
@@ -1642,6 +1642,54 @@ static int bus_append_root_hash_signature(sd_bus_message *m, const char *field,
         return bus_append_byte_array(m, field, roothash_sig_decoded, roothash_sig_decoded_size);
 }
 
+static int bus_append_root_image_options(sd_bus_message *m, const char *field, const char *eq) {
+        _cleanup_strv_free_ char **l = NULL;
+        const char *p = eq;
+        int r;
+
+        r = sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, "sv");
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, field);
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        r = sd_bus_message_open_container(m, 'v', "a(ss)");
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        r = sd_bus_message_open_container(m, 'a', "(ss)");
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        r = strv_split_colon_pairs(&l, p);
+        if (r < 0)
+                return log_error_errno(r, "Failed to parse argument: %m");
+
+        STRV_FOREACH_PAIR(first, second, l) {
+                r = sd_bus_message_append(m, "(ss)",
+                                          !isempty(*second) ? *first : "root",
+                                          !isempty(*second) ? *second : *first);
+                if (r < 0)
+                        return bus_log_create_error(r);
+        }
+
+        r = sd_bus_message_close_container(m);
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        r = sd_bus_message_close_container(m);
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        r = sd_bus_message_close_container(m);
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        return 1;
+}
+
 static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) {
         if (STR_IN_SET(field, "DevicePolicy",
                               "Slice",
@@ -1994,52 +2042,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
         if (streq(field, "RootHashSignature"))
                 return bus_append_root_hash_signature(m, field, eq);
 
-        if (streq(field, "RootImageOptions")) {
-                _cleanup_strv_free_ char **l = NULL;
-                const char *p = eq;
-
-                r = sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, "sv");
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, field);
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                r = sd_bus_message_open_container(m, 'v', "a(ss)");
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                r = sd_bus_message_open_container(m, 'a', "(ss)");
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                r = strv_split_colon_pairs(&l, p);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to parse argument: %m");
-
-                STRV_FOREACH_PAIR(first, second, l) {
-                        r = sd_bus_message_append(m, "(ss)",
-                                                  !isempty(*second) ? *first : "root",
-                                                  !isempty(*second) ? *second : *first);
-                        if (r < 0)
-                                return bus_log_create_error(r);
-                }
-
-                r = sd_bus_message_close_container(m);
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                r = sd_bus_message_close_container(m);
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                r = sd_bus_message_close_container(m);
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                return 1;
-        }
+        if (streq(field, "RootImageOptions"))
+                return bus_append_root_image_options(m, field, eq);
 
         if (streq(field, "MountImages")) {
                 const char *p = eq;