|
|
84b277 |
From e1036b1b5133141949bea166fb2cb6cdbfec3be0 Mon Sep 17 00:00:00 2001
|
|
|
84b277 |
From: Lukas Nykryn <lnykryn@redhat.com>
|
|
|
84b277 |
Date: Fri, 12 Sep 2014 13:27:36 +0200
|
|
|
84b277 |
Subject: [PATCH] systemctl: unbreak switchroot
|
|
|
84b277 |
|
|
|
84b277 |
rhel-only patch
|
|
|
84b277 |
cad8ec5980d63253586d9f884649c45eed0667a1 backport broke it
|
|
|
84b277 |
|
|
|
84b277 |
Related: #1138546
|
|
|
84b277 |
---
|
|
|
84b277 |
src/systemctl/systemctl.c | 26 ++++++++++++++------------
|
|
|
84b277 |
1 file changed, 14 insertions(+), 12 deletions(-)
|
|
|
84b277 |
|
|
|
84b277 |
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
|
|
|
84b277 |
index 90a80bd..ebc8caa 100644
|
|
|
84b277 |
--- a/src/systemctl/systemctl.c
|
|
|
84b277 |
+++ b/src/systemctl/systemctl.c
|
|
|
84b277 |
@@ -4147,8 +4147,8 @@ static int show_enviroment(DBusConnection *bus, char **args) {
|
|
|
84b277 |
}
|
|
|
84b277 |
|
|
|
84b277 |
static int switch_root(DBusConnection *bus, char **args) {
|
|
|
84b277 |
- _cleanup_free_ char *cmdline_init = NULL;
|
|
|
84b277 |
- const char *root, *init;
|
|
|
84b277 |
+ _cleanup_free_ char *init = NULL;
|
|
|
84b277 |
+ const char *root;
|
|
|
84b277 |
unsigned l;
|
|
|
84b277 |
int r;
|
|
|
84b277 |
|
|
|
84b277 |
@@ -4161,23 +4161,20 @@ static int switch_root(DBusConnection *bus, char **args) {
|
|
|
84b277 |
root = args[1];
|
|
|
84b277 |
|
|
|
84b277 |
if (l >= 3)
|
|
|
84b277 |
- init = args[2];
|
|
|
84b277 |
+ init = strdup(args[2]);
|
|
|
84b277 |
else {
|
|
|
84b277 |
r = parse_env_file("/proc/cmdline", WHITESPACE,
|
|
|
84b277 |
- "init", &cmdline_init,
|
|
|
84b277 |
+ "init", &init,
|
|
|
84b277 |
NULL);
|
|
|
84b277 |
if (r < 0)
|
|
|
84b277 |
log_debug("Failed to parse /proc/cmdline: %s", strerror(-r));
|
|
|
84b277 |
|
|
|
84b277 |
- init = cmdline_init;
|
|
|
84b277 |
+ if (!init)
|
|
|
84b277 |
+ init = strdup("");
|
|
|
84b277 |
}
|
|
|
84b277 |
- if (!init)
|
|
|
84b277 |
- return log_oom();
|
|
|
84b277 |
|
|
|
84b277 |
- if (isempty(init))
|
|
|
84b277 |
- init = NULL;
|
|
|
84b277 |
|
|
|
84b277 |
- if (init) {
|
|
|
84b277 |
+ if (!isempty(init)) {
|
|
|
84b277 |
const char *root_systemd_path = NULL, *root_init_path = NULL;
|
|
|
84b277 |
|
|
|
84b277 |
root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
|
|
|
84b277 |
@@ -4185,10 +4182,15 @@ static int switch_root(DBusConnection *bus, char **args) {
|
|
|
84b277 |
|
|
|
84b277 |
/* If the passed init is actually the same as the
|
|
|
84b277 |
* systemd binary, then let's suppress it. */
|
|
|
84b277 |
- if (files_same(root_init_path, root_systemd_path) > 0)
|
|
|
84b277 |
- init = NULL;
|
|
|
84b277 |
+ if (files_same(root_init_path, root_systemd_path) > 0) {
|
|
|
84b277 |
+ free(init);
|
|
|
84b277 |
+ init = strdup("");
|
|
|
84b277 |
+ }
|
|
|
84b277 |
}
|
|
|
84b277 |
|
|
|
84b277 |
+ if (!init)
|
|
|
84b277 |
+ return log_oom();
|
|
|
84b277 |
+
|
|
|
84b277 |
log_debug("Switching root - root: %s; init: %s", root, strna(init));
|
|
|
84b277 |
|
|
|
84b277 |
return bus_method_call_with_reply(
|