From db12f8432762edd4ab03ff23d1ebdf002fa59348 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 10 Jul 2024 22:27:21 +0200 Subject: [PATCH] run: clean up ExecCommandFlags serialization 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 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index 65653368663..e86e89b51b3 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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); -- 2.47.3