From 619d378f55bfd89a5194043cc62e8e1e223261b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 18 Jun 2025 16:17:50 +0200 Subject: [PATCH] shared/bus-unit-util: define helper for DeviceAllow= --- src/shared/bus-unit-util.c | 43 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 611d8a18583..1eb3fa30d4a 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -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) { -- 2.47.3