From 7c4b4a93d60ab147722c3fa63674213a0734ff37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 18 Jun 2025 16:45:49 +0200 Subject: [PATCH] shared/bus-unit-util: define helper function for EnvironmentFile= --- src/shared/bus-unit-util.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index a54070d6148..774dbc78d41 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -967,6 +967,21 @@ static int bus_append_nft_set(sd_bus_message *m, const char *field, const char * return 1; } +static int bus_append_environment_files(sd_bus_message *m, const char *field, const char *eq) { + int r; + + if (isempty(eq)) + r = sd_bus_message_append(m, "(sv)", "EnvironmentFiles", "a(sb)", 0); + else + r = sd_bus_message_append(m, "(sv)", "EnvironmentFiles", "a(sb)", 1, + eq[0] == '-' ? eq + 1 : eq, + eq[0] == '-'); + 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", @@ -1234,18 +1249,9 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con "PassEnvironment")) return bus_append_strv(m, field, eq, /* separator= */ NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE); - if (streq(field, "EnvironmentFile")) { - if (isempty(eq)) - r = sd_bus_message_append(m, "(sv)", "EnvironmentFiles", "a(sb)", 0); - else - r = sd_bus_message_append(m, "(sv)", "EnvironmentFiles", "a(sb)", 1, - eq[0] == '-' ? eq + 1 : eq, - eq[0] == '-'); - if (r < 0) - return bus_log_create_error(r); + if (streq(field, "EnvironmentFile")) + return bus_append_environment_files(m, field, eq); - return 1; - } if (STR_IN_SET(field, "SetCredential", "SetCredentialEncrypted")) { r = sd_bus_message_open_container(m, 'r', "sv"); -- 2.47.3