From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Jun 2025 12:23:10 +0000 (+0200) Subject: shared/bus-unit-util: define helper for MountImages= X-Git-Tag: v258-rc1~183^2~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1c202720bebb2221113f1317c21b797c84627763;p=thirdparty%2Fsystemd.git shared/bus-unit-util: define helper for MountImages= --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 9d22a60d344..81e59aaa76f 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1690,6 +1690,112 @@ static int bus_append_root_image_options(sd_bus_message *m, const char *field, c return 1; } +static int bus_append_mount_images(sd_bus_message *m, const char *field, const char *eq) { + 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(ssba(ss))"); + if (r < 0) + return bus_log_create_error(r); + + r = sd_bus_message_open_container(m, 'a', "(ssba(ss))"); + if (r < 0) + return bus_log_create_error(r); + + for (;;) { + _cleanup_free_ char *first = NULL, *second = NULL, *tuple = NULL; + const char *q = NULL, *source = NULL; + bool permissive = false; + + r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); + if (r < 0) + return log_error_errno(r, "Failed to parse %s property: %s", field, eq); + if (r == 0) + break; + + q = tuple; + r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &first, &second); + if (r < 0) + return log_error_errno(r, "Failed to parse %s property: %s", field, eq); + if (r == 0) + continue; + + source = first; + if (source[0] == '-') { + permissive = true; + source++; + } + + if (isempty(second)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Missing argument after ':' for %s: %s", field, eq); + + r = sd_bus_message_open_container(m, 'r', "ssba(ss)"); + if (r < 0) + return bus_log_create_error(r); + + r = sd_bus_message_append(m, "ssb", source, second, permissive); + 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); + + for (;;) { + _cleanup_free_ char *partition = NULL, *mount_options = NULL; + + r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options); + if (r < 0) + return log_error_errno(r, "Failed to parse %s property: %s", field, eq); + if (r == 0) + break; + /* Single set of options, applying to the root partition/single filesystem */ + if (r == 1) { + r = sd_bus_message_append(m, "(ss)", "root", partition); + if (r < 0) + return bus_log_create_error(r); + + break; + } + + r = sd_bus_message_append(m, "(ss)", partition, mount_options); + 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); + + 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", @@ -2045,111 +2151,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con if (streq(field, "RootImageOptions")) return bus_append_root_image_options(m, field, eq); - if (streq(field, "MountImages")) { - 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(ssba(ss))"); - if (r < 0) - return bus_log_create_error(r); - - r = sd_bus_message_open_container(m, 'a', "(ssba(ss))"); - if (r < 0) - return bus_log_create_error(r); - - for (;;) { - _cleanup_free_ char *first = NULL, *second = NULL, *tuple = NULL; - const char *q = NULL, *source = NULL; - bool permissive = false; - - r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); - if (r < 0) - return log_error_errno(r, "Failed to parse MountImages= property: %s", eq); - if (r == 0) - break; - - q = tuple; - r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &first, &second); - if (r < 0) - return log_error_errno(r, "Failed to parse MountImages= property: %s", eq); - if (r == 0) - continue; - - source = first; - if (source[0] == '-') { - permissive = true; - source++; - } - - if (isempty(second)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Missing argument after ':': %s", - eq); - - r = sd_bus_message_open_container(m, 'r', "ssba(ss)"); - if (r < 0) - return bus_log_create_error(r); - - r = sd_bus_message_append(m, "ssb", source, second, permissive); - 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); - - for (;;) { - _cleanup_free_ char *partition = NULL, *mount_options = NULL; - - r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options); - if (r < 0) - return log_error_errno(r, "Failed to parse MountImages= property: %s", eq); - if (r == 0) - break; - /* Single set of options, applying to the root partition/single filesystem */ - if (r == 1) { - r = sd_bus_message_append(m, "(ss)", "root", partition); - if (r < 0) - return bus_log_create_error(r); - - break; - } - - r = sd_bus_message_append(m, "(ss)", partition, mount_options); - 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); - - 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, "MountImages")) + return bus_append_mount_images(m, field, eq); if (streq(field, "ExtensionImages")) { const char *p = eq;