]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: clean up ExecCommandFlags serialization 33790/head
authorMike Yuan <me@yhndnzj.com>
Wed, 10 Jul 2024 20:27:21 +0000 (22:27 +0200)
committerMike Yuan <me@yhndnzj.com>
Sat, 20 Jul 2024 07:37:34 +0000 (09:37 +0200)
The current behavior is actually OK, since use_ex_prop = !arg_expand_environment,
but that's very implicit and using STRV_MAKE() this way feels icky.
Let's make this more readable, by using exec_command_flags_to_strv().

src/run/run.c

index 6565336866325a778b0d954ec4128dc22844fd25..e86e89b51b386e7243be7d32dcd00733fe6a17cd 100644 (file)
@@ -21,6 +21,7 @@
 #include "chase.h"
 #include "env-util.h"
 #include "escape.h"
+#include "exec-util.h"
 #include "exit-status.h"
 #include "fd-util.h"
 #include "format-util.h"
@@ -1246,12 +1247,17 @@ static int transient_service_set_properties(sd_bus_message *m, const char *pty_p
                 if (r < 0)
                         return bus_log_create_error(r);
 
-                if (use_ex_prop)
-                        r = sd_bus_message_append_strv(
-                                        m,
-                                        STRV_MAKE(arg_expand_environment > 0 ? NULL : "no-env-expand",
-                                                  arg_ignore_failure ? "ignore-failure" : NULL));
-                else
+                if (use_ex_prop) {
+                        _cleanup_strv_free_ char **opts = NULL;
+
+                        r = exec_command_flags_to_strv(
+                                        (arg_expand_environment > 0 ? 0 : EXEC_COMMAND_NO_ENV_EXPAND)|(arg_ignore_failure ? EXEC_COMMAND_IGNORE_FAILURE : 0),
+                                        &opts);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to format execute flags: %m");
+
+                        r = sd_bus_message_append_strv(m, opts);
+                } else
                         r = sd_bus_message_append(m, "b", arg_ignore_failure);
                 if (r < 0)
                         return bus_log_create_error(r);