summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-08-31 18:51:25 +0200
committerGitHub <noreply@github.com>2017-08-31 18:51:25 +0200
commitdfff69bfc49e06c1acf3560478974260e95b3c51 (patch)
tree4438e93c64cf3c87855adfcdc5776688ec6512ab /src/systemctl/systemctl.c
parentnetworkd: Allow tunnels to be created without .network (#6701) (diff)
parentsystemctl: improve readability of start_unit() (diff)
downloadsystemd-dfff69bfc49e06c1acf3560478974260e95b3c51.tar.xz
systemd-dfff69bfc49e06c1acf3560478974260e95b3c51.zip
Merge pull request #6637 from sourcejedi/systemctl_cleanup
systemctl: improve readability of start_unit()
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r--src/systemctl/systemctl.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 79e9ac95c1..a533132abb 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -145,7 +145,6 @@ static char *arg_root = NULL;
static usec_t arg_when = 0;
static char *argv_cmdline = NULL;
static enum action {
- _ACTION_INVALID,
ACTION_SYSTEMCTL,
ACTION_HALT,
ACTION_POWEROFF,
@@ -166,7 +165,8 @@ static enum action {
ACTION_REEXEC,
ACTION_RUNLEVEL,
ACTION_CANCEL_SHUTDOWN,
- _ACTION_MAX
+ _ACTION_MAX,
+ _ACTION_INVALID = -1
} arg_action = ACTION_SYSTEMCTL;
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
static const char *arg_host = NULL;
@@ -3052,7 +3052,7 @@ static const struct {
static enum action verb_to_action(const char *verb) {
enum action i;
- for (i = _ACTION_INVALID; i < _ACTION_MAX; i++)
+ for (i = 0; i < _ACTION_MAX; i++)
if (streq_ptr(action_table[i].verb, verb))
return i;
@@ -3068,8 +3068,8 @@ static int start_unit(int argc, char *argv[], void *userdata) {
char **name;
int r = 0;
- if (arg_wait && !strstr(argv[0], "start")) {
- log_error("--wait may only be used with a command that starts units.");
+ if (arg_wait && !STR_IN_SET(argv[0], "start", "restart")) {
+ log_error("--wait may only be used with the 'start' or 'restart' commands.");
return -EINVAL;
}
@@ -3085,22 +3085,30 @@ static int start_unit(int argc, char *argv[], void *userdata) {
if (arg_action == ACTION_SYSTEMCTL) {
enum action action;
- method = verb_to_method(argv[0]);
action = verb_to_action(argv[0]);
- if (streq(argv[0], "isolate")) {
- mode = "isolate";
- suffix = ".target";
- } else
- mode = action_table[action].mode ?: arg_job_mode;
+ if (action != _ACTION_INVALID) {
+ method = "StartUnit";
+ mode = action_table[action].mode;
+ one_name = action_table[action].target;
+ } else {
+ if (streq(argv[0], "isolate")) {
+ method = "StartUnit";
+ mode = "isolate";
- one_name = action_table[action].target;
+ suffix = ".target";
+ } else {
+ method = verb_to_method(argv[0]);
+ mode = arg_job_mode;
+ }
+ one_name = NULL;
+ }
} else {
assert(arg_action < ELEMENTSOF(action_table));
assert(action_table[arg_action].target);
+ assert(action_table[arg_action].mode);
method = "StartUnit";
-
mode = action_table[arg_action].mode;
one_name = action_table[arg_action].target;
}