From: Lennart Poettering Date: Thu, 11 Nov 2021 08:32:32 +0000 (+0100) Subject: escape: add flags argument to quote_command_line() X-Git-Tag: v250-rc1~306^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ef15008ccf6935bb53539750ed828a969d37929;p=thirdparty%2Fsystemd.git escape: add flags argument to quote_command_line() That way, we can reuse the call at one more place (see later patch). --- diff --git a/src/basic/escape.c b/src/basic/escape.c index 4bb98f9342b..25f3861a5fe 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -544,7 +544,7 @@ char* shell_maybe_quote(const char *s, ShellEscapeFlags flags) { return str_realloc(buf); } -char* quote_command_line(char **argv) { +char* quote_command_line(char **argv, ShellEscapeFlags flags) { _cleanup_free_ char *result = NULL; assert(argv); @@ -553,7 +553,7 @@ char* quote_command_line(char **argv) { STRV_FOREACH(a, argv) { _cleanup_free_ char *t = NULL; - t = shell_maybe_quote(*a, SHELL_ESCAPE_EMPTY); + t = shell_maybe_quote(*a, flags); if (!t) return NULL; diff --git a/src/basic/escape.h b/src/basic/escape.h index d490510deb1..318da6f2203 100644 --- a/src/basic/escape.h +++ b/src/basic/escape.h @@ -69,4 +69,4 @@ char* escape_non_printable_full(const char *str, size_t console_width, XEscapeFl char* shell_escape(const char *s, const char *bad); char* shell_maybe_quote(const char *s, ShellEscapeFlags flags); -char* quote_command_line(char **argv); +char* quote_command_line(char **argv, ShellEscapeFlags flags); diff --git a/src/core/execute.c b/src/core/execute.c index 425e3e5a37c..6f19f5024e3 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -3999,16 +3999,15 @@ static int exec_child( exec_context_tty_reset(context, params); if (unit_shall_confirm_spawn(unit)) { - const char *vc = params->confirm_spawn; _cleanup_free_ char *cmdline = NULL; - cmdline = quote_command_line(command->argv); + cmdline = quote_command_line(command->argv, SHELL_ESCAPE_EMPTY); if (!cmdline) { *exit_status = EXIT_MEMORY; return log_oom(); } - r = ask_for_confirmation(context, vc, unit, cmdline); + r = ask_for_confirmation(context, params->confirm_spawn, unit, cmdline); if (r != CONFIRM_EXECUTE) { if (r == CONFIRM_PRETEND_SUCCESS) { *exit_status = EXIT_SUCCESS; @@ -4884,7 +4883,7 @@ static int exec_child( if (DEBUG_LOGGING) { _cleanup_free_ char *line = NULL; - line = quote_command_line(final_argv); + line = quote_command_line(final_argv, SHELL_ESCAPE_EMPTY); if (!line) { *exit_status = EXIT_MEMORY; return log_oom(); @@ -4976,7 +4975,7 @@ int exec_spawn(Unit *unit, if (r < 0) return log_unit_error_errno(unit, r, "Failed to load environment files: %m"); - line = quote_command_line(command->argv); + line = quote_command_line(command->argv, SHELL_ESCAPE_EMPTY); if (!line) return log_oom(); @@ -6230,7 +6229,7 @@ static void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) { prefix = strempty(prefix); prefix2 = strjoina(prefix, "\t"); - cmd = quote_command_line(c->argv); + cmd = quote_command_line(c->argv, SHELL_ESCAPE_EMPTY); fprintf(f, "%sCommand Line: %s\n", prefix, cmd ? cmd : strerror_safe(ENOMEM)); diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 9c448e36394..a603764c27e 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -968,7 +968,7 @@ int bus_socket_exec(sd_bus *b) { _cleanup_free_ char *line = NULL; if (b->exec_argv) - line = quote_command_line(b->exec_argv); + line = quote_command_line(b->exec_argv, SHELL_ESCAPE_EMPTY); log_debug("sd-bus: starting bus%s%s with %s%s", b->description ? " " : "", strempty(b->description), diff --git a/src/test/test-escape.c b/src/test/test-escape.c index 3fd318653c2..75aa86bf697 100644 --- a/src/test/test-escape.c +++ b/src/test/test-escape.c @@ -206,7 +206,7 @@ static void test_shell_maybe_quote(void) { static void test_quote_command_line_one(char **argv, const char *expected) { _cleanup_free_ char *s; - assert_se(s = quote_command_line(argv)); + assert_se(s = quote_command_line(argv, SHELL_ESCAPE_EMPTY)); log_info("%s", s); assert_se(streq(s, expected)); }