diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 0a65f4ee85..271d0bb90c 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -693,8 +693,7 @@ static int parse_argv(int argc, char *argv[]) { * and its own controlling terminal. If one of the tasks does handle a password, the remaining tasks will be * terminated. */ -static int ask_on_this_console(const char *tty, pid_t *ret_pid, char *argv[]) { - _cleanup_strv_free_ char **arguments = NULL; +static int ask_on_this_console(const char *tty, pid_t *ret_pid, char **arguments) { static const struct sigaction sigchld = { .sa_handler = nop_signal_handler, .sa_flags = SA_NOCLDSTOP | SA_RESTART, @@ -705,10 +704,6 @@ static int ask_on_this_console(const char *tty, pid_t *ret_pid, char *argv[]) { }; int r; - arguments = strv_copy(argv); - if (!arguments) - return log_oom(); - assert_se(sigaction(SIGCHLD, &sigchld, NULL) >= 0); assert_se(sigaction(SIGHUP, &sighup, NULL) >= 0); assert_se(sigprocmask_many(SIG_UNBLOCK, NULL, SIGHUP, SIGCHLD, -1) >= 0); @@ -797,7 +792,7 @@ static void terminate_agents(Set *pids) { static int ask_on_consoles(char *argv[]) { _cleanup_set_free_ Set *pids = NULL; - _cleanup_strv_free_ char **consoles = NULL; + _cleanup_strv_free_ char **consoles = NULL, **arguments = NULL; siginfo_t status = {}; char **tty; pid_t pid; @@ -811,9 +806,13 @@ static int ask_on_consoles(char *argv[]) { if (!pids) return log_oom(); + arguments = strv_copy(argv); + if (!arguments) + return log_oom(); + /* Start an agent on each console. */ STRV_FOREACH(tty, consoles) { - r = ask_on_this_console(*tty, &pid, argv); + r = ask_on_this_console(*tty, &pid, arguments); if (r < 0) return r;