]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-unit-util: define helper function for EnvironmentFile=
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 18 Jun 2025 14:45:49 +0000 (16:45 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 3 Jul 2025 08:37:34 +0000 (10:37 +0200)
src/shared/bus-unit-util.c

index a54070d614862acc5057154c208494e1b9334f0f..774dbc78d41ba009dec75ace74a1a40d5a2c50c1 100644 (file)
@@ -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");