]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ask-passwd: slightly optimize handling arguments
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Apr 2019 03:40:44 +0000 (12:40 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 4 Apr 2019 06:07:03 +0000 (08:07 +0200)
It is not necessary to copy arguments for each console.

src/tty-ask-password-agent/tty-ask-password-agent.c

index 0a65f4ee8562bf73d0f37ad257f48b616e5f4ec5..271d0bb90ce0638ccaa86da52a10cc85c159d0cd 100644 (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;