teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0449-systemctl-split-out-extra-args-generation-into-helpe.patch

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