escape: add flags argument to quote_command_line()

That way, we can reuse the call at one more place (see later patch).
This commit is contained in:
Lennart Poettering
2021-11-11 09:32:32 +01:00
parent a704137c20
commit 4ef15008cc
5 changed files with 10 additions and 11 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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));

View File

@@ -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),

View File

@@ -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));
}