From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Jun 2025 12:21:43 +0000 (+0200) Subject: shared/bus-unit-util: define helper for RootImageOptions= X-Git-Tag: v258-rc1~183^2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79decd4e4912eb03f5d8dd403f69c87601788906;p=thirdparty%2Fsystemd.git shared/bus-unit-util: define helper for RootImageOptions= --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index a8925c1a002..9d22a60d344 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -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;