From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Jun 2025 11:53:25 +0000 (+0200) Subject: shared/bus-unit-util: define helper for IODeviceWeight= X-Git-Tag: v258-rc1~183^2~51 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=335f7c7f0158f87261c7b19879a8f24bf363739c;p=thirdparty%2Fsystemd.git shared/bus-unit-util: define helper for IODeviceWeight= --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 5254062f04d..ec8657d8197 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -430,6 +430,34 @@ static int bus_append_parse_cgroup_io_limit(sd_bus_message *m, const char *field return 1; } +static int bus_append_parse_io_device_weight(sd_bus_message *m, const char *field, const char *eq) { + int r; + + if (isempty(eq)) + r = sd_bus_message_append(m, "(sv)", field, "a(st)", 0); + else { + const char *e = strchr(eq, ' '); + if (!e) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Failed to parse %s value %s.", + field, eq); + + const char *path = strndupa_safe(eq, e - eq); + const char *weight = e + 1; + + uint64_t u; + r = safe_atou64(weight, &u); + if (r < 0) + return log_error_errno(r, "Failed to parse %s value %s: %m", field, weight); + + r = sd_bus_message_append(m, "(sv)", field, "a(st)", 1, path, u); + } + 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; @@ -798,34 +826,8 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons if (cgroup_io_limit_type_from_string(field) >= 0) return bus_append_parse_cgroup_io_limit(m, field, eq); - if (streq(field, "IODeviceWeight")) { - if (isempty(eq)) - r = sd_bus_message_append(m, "(sv)", field, "a(st)", 0); - else { - const char *path, *weight, *e; - uint64_t u; - - e = strchr(eq, ' '); - if (!e) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Failed to parse %s value %s.", - field, eq); - - path = strndupa_safe(eq, e - eq); - weight = e+1; - - r = safe_atou64(weight, &u); - if (r < 0) - return log_error_errno(r, "Failed to parse %s value %s: %m", field, weight); - - r = sd_bus_message_append(m, "(sv)", field, "a(st)", 1, path, u); - } - - if (r < 0) - return bus_log_create_error(r); - - return 1; - } + if (streq(field, "IODeviceWeight")) + return bus_append_parse_io_device_weight(m, field, eq); if (streq(field, "IODeviceLatencyTargetSec")) { const char *field_usec = "IODeviceLatencyTargetUSec";