1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

ask-passwd: slightly optimize handling arguments

It is not necessary to copy arguments for each console.
This commit is contained in:
Yu Watanabe 2019-04-04 12:40:44 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent 8c69fe79df
commit 6e79d2b5a4

View File

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