Skip to content

Commit ea71b46

Browse files
committed
systemctl: move telinit execcing out of parse_argv()
With this change, parse_argv() does parsing, without any real actions. Fully untested ;)
1 parent 54d04cd commit ea71b46

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/systemctl/systemctl-compat-telinit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

33
#include <getopt.h>
4+
#include <unistd.h>
45

56
#include "alloc-util.h"
67
#include "pretty-print.h"
8+
#include "rlimit-util.h"
79
#include "systemctl-compat-telinit.h"
810
#include "systemctl-daemon-reload.h"
911
#include "systemctl-start-unit.h"
@@ -150,3 +152,11 @@ int reload_with_fallback(void) {
150152

151153
return 0;
152154
}
155+
156+
int exec_telinit(char *argv[]) {
157+
(void) rlimit_nofile_safe();
158+
execv(TELINIT, argv);
159+
160+
return log_error_errno(SYNTHETIC_ERRNO(EIO),
161+
"Couldn't find an alternative telinit implementation to spawn.");
162+
}

src/systemctl/systemctl-compat-telinit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
int telinit_parse_argv(int argc, char *argv[]);
55
int start_with_fallback(void);
66
int reload_with_fallback(void);
7+
int exec_telinit(char *argv[]);

src/systemctl/systemctl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,8 @@ static int parse_argv(int argc, char *argv[]) {
973973
/* Hmm, so some other init system is running, we need to forward this request
974974
* to it. */
975975

976-
(void) rlimit_nofile_safe();
977-
execv(TELINIT, argv);
978-
979-
return log_error_errno(SYNTHETIC_ERRNO(EIO),
980-
"Couldn't find an alternative telinit implementation to spawn.");
976+
arg_action = ACTION_TELINIT;
977+
return 1;
981978
}
982979

983980
} else if (strstr(program_invocation_short_name, "runlevel")) {
@@ -1143,6 +1140,10 @@ static int run(int argc, char *argv[]) {
11431140
r = runlevel_main();
11441141
break;
11451142

1143+
case ACTION_TELINIT:
1144+
r = exec_telinit(argv);
1145+
break;
1146+
11461147
case ACTION_EXIT:
11471148
case ACTION_SUSPEND:
11481149
case ACTION_HIBERNATE:

src/systemctl/systemctl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum action {
2929
ACTION_RELOAD,
3030
ACTION_REEXEC,
3131
ACTION_RUNLEVEL,
32+
ACTION_TELINIT,
3233
ACTION_CANCEL_SHUTDOWN,
3334
_ACTION_MAX,
3435
_ACTION_INVALID = -1

0 commit comments

Comments
 (0)