dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
bd1529
From cfb124260a0a9e68102a373c0d136f792e2d4ea7 Mon Sep 17 00:00:00 2001
bd1529
From: Lennart Poettering <lennart@poettering.net>
bd1529
Date: Tue, 26 Mar 2019 16:19:35 +0100
bd1529
Subject: [PATCH] systemctl: split out extra args generation into helper
bd1529
 function of its own
bd1529
bd1529
(cherry picked from commit 94369fc0663255bbd327f97dba288ececf51a514)
bd1529
bd1529
Related: #846319
bd1529
---
bd1529
 src/systemctl/systemctl.c | 36 +++++++++++++++++++++---------------
bd1529
 1 file changed, 21 insertions(+), 15 deletions(-)
bd1529
bd1529
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
bd1529
index 4af9deb98d..e7a8fd559f 100644
bd1529
--- a/src/systemctl/systemctl.c
bd1529
+++ b/src/systemctl/systemctl.c
bd1529
@@ -3002,6 +3002,25 @@ static enum action verb_to_action(const char *verb) {
bd1529
         return _ACTION_INVALID;
bd1529
 }
bd1529
 
bd1529
+static const char** make_extra_args(const char *extra_args[static 4]) {
bd1529
+        size_t n = 0;
bd1529
+
bd1529
+        if (arg_scope != UNIT_FILE_SYSTEM)
bd1529
+                extra_args[n++] = "--user";
bd1529
+
bd1529
+        if (arg_transport == BUS_TRANSPORT_REMOTE) {
bd1529
+                extra_args[n++] = "-H";
bd1529
+                extra_args[n++] = arg_host;
bd1529
+        } else if (arg_transport == BUS_TRANSPORT_MACHINE) {
bd1529
+                extra_args[n++] = "-M";
bd1529
+                extra_args[n++] = arg_host;
bd1529
+        } else
bd1529
+                assert(arg_transport == BUS_TRANSPORT_LOCAL);
bd1529
+
bd1529
+        extra_args[n] = NULL;
bd1529
+        return extra_args;
bd1529
+}
bd1529
+
bd1529
 static int start_unit(int argc, char *argv[], void *userdata) {
bd1529
         _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
bd1529
         _cleanup_(wait_context_free) WaitContext wait_context = {};
bd1529
@@ -3103,22 +3122,9 @@ static int start_unit(int argc, char *argv[], void *userdata) {
bd1529
         }
bd1529
 
bd1529
         if (!arg_no_block) {
bd1529
-                const char* extra_args[4] = {};
bd1529
-                int arg_count = 0;
bd1529
-
bd1529
-                if (arg_scope != UNIT_FILE_SYSTEM)
bd1529
-                        extra_args[arg_count++] = "--user";
bd1529
-
bd1529
-                assert(IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_REMOTE, BUS_TRANSPORT_MACHINE));
bd1529
-                if (arg_transport == BUS_TRANSPORT_REMOTE) {
bd1529
-                        extra_args[arg_count++] = "-H";
bd1529
-                        extra_args[arg_count++] = arg_host;
bd1529
-                } else if (arg_transport == BUS_TRANSPORT_MACHINE) {
bd1529
-                        extra_args[arg_count++] = "-M";
bd1529
-                        extra_args[arg_count++] = arg_host;
bd1529
-                }
bd1529
+                const char* extra_args[4];
bd1529
 
bd1529
-                r = bus_wait_for_jobs(w, arg_quiet, extra_args);
bd1529
+                r = bus_wait_for_jobs(w, arg_quiet, make_extra_args(extra_args));
bd1529
                 if (r < 0)
bd1529
                         return r;
bd1529