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