From ea71b4604b172cb48bd58219800afcf127d02163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 7 Feb 2021 17:35:06 +0100 Subject: [PATCH] systemctl: move telinit execcing out of parse_argv() With this change, parse_argv() does parsing, without any real actions. Fully untested ;) --- src/systemctl/systemctl-compat-telinit.c | 10 ++++++++++ src/systemctl/systemctl-compat-telinit.h | 1 + src/systemctl/systemctl.c | 11 ++++++----- src/systemctl/systemctl.h | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/systemctl/systemctl-compat-telinit.c b/src/systemctl/systemctl-compat-telinit.c index f67361ea90..f0e9ca8d79 100644 --- a/src/systemctl/systemctl-compat-telinit.c +++ b/src/systemctl/systemctl-compat-telinit.c @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include "alloc-util.h" #include "pretty-print.h" +#include "rlimit-util.h" #include "systemctl-compat-telinit.h" #include "systemctl-daemon-reload.h" #include "systemctl-start-unit.h" @@ -150,3 +152,11 @@ int reload_with_fallback(void) { return 0; } + +int exec_telinit(char *argv[]) { + (void) rlimit_nofile_safe(); + execv(TELINIT, argv); + + return log_error_errno(SYNTHETIC_ERRNO(EIO), + "Couldn't find an alternative telinit implementation to spawn."); +} diff --git a/src/systemctl/systemctl-compat-telinit.h b/src/systemctl/systemctl-compat-telinit.h index 1a2bcd4405..783c3878a0 100644 --- a/src/systemctl/systemctl-compat-telinit.h +++ b/src/systemctl/systemctl-compat-telinit.h @@ -4,3 +4,4 @@ int telinit_parse_argv(int argc, char *argv[]); int start_with_fallback(void); int reload_with_fallback(void); +int exec_telinit(char *argv[]); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index f60187e43a..cb901881c9 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -973,11 +973,8 @@ static int parse_argv(int argc, char *argv[]) { /* Hmm, so some other init system is running, we need to forward this request * to it. */ - (void) rlimit_nofile_safe(); - execv(TELINIT, argv); - - return log_error_errno(SYNTHETIC_ERRNO(EIO), - "Couldn't find an alternative telinit implementation to spawn."); + arg_action = ACTION_TELINIT; + return 1; } } else if (strstr(program_invocation_short_name, "runlevel")) { @@ -1143,6 +1140,10 @@ static int run(int argc, char *argv[]) { r = runlevel_main(); break; + case ACTION_TELINIT: + r = exec_telinit(argv); + break; + case ACTION_EXIT: case ACTION_SUSPEND: case ACTION_HIBERNATE: diff --git a/src/systemctl/systemctl.h b/src/systemctl/systemctl.h index 34650ebb44..f7ee358ce1 100644 --- a/src/systemctl/systemctl.h +++ b/src/systemctl/systemctl.h @@ -29,6 +29,7 @@ enum action { ACTION_RELOAD, ACTION_REEXEC, ACTION_RUNLEVEL, + ACTION_TELINIT, ACTION_CANCEL_SHUTDOWN, _ACTION_MAX, _ACTION_INVALID = -1