[systemd-devel] [PATCH 2/2] [V4] systemctl: for switch-root check, if we switch to a systemd init
harald at redhat.com
harald at redhat.com
Thu Mar 6 07:35:02 PST 2014
From: Harald Hoyer <harald at redhat.com>
If "systemctl switch-root" is called with a specific "INIT" or
/proc/cmdline contains "init=", then systemd would not serialize
itsself.
Let systemctl check, if the new init is in the standard systemd
installation path and if so, clear the INIT parameter,
to let systemd serialize itsself.
---
src/systemctl/systemctl.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index f395265..e2588e5 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4295,19 +4295,31 @@ static int switch_root(sd_bus *bus, char **args) {
root = args[1];
- if (l >= 3)
+ if (l >= 3) {
init = strdup(args[2]);
- else {
+ if (!init)
+ return log_oom();
+ } else {
parse_env_file("/proc/cmdline", WHITESPACE,
"init", &init,
NULL);
-
- if (!init)
- init = strdup("");
}
- if (!init)
- return log_oom();
+ if (!isempty(init)) {
+ char *root_systemd_path = NULL;
+ _cleanup_free_ char *root_init_path = NULL;
+
+ root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
+
+ root_init_path = strjoin(root, "/", init, NULL);
+ if (!root_init_path)
+ return log_oom();
+
+ if (files_same(root_init_path, root_systemd_path) > 0) {
+ free(init);
+ init = NULL;
+ }
+ }
log_debug("switching root - root: %s; init: %s", root, init);
--
1.8.5.3
More information about the systemd-devel
mailing list