|
Adam Williamson |
4c60d7 |
From acc28e2e3037d689d6481e4664925cf31d4d087b Mon Sep 17 00:00:00 2001
|
|
Adam Williamson |
4c60d7 |
From: Franck Bui <fbui@suse.com>
|
|
Adam Williamson |
4c60d7 |
Date: Thu, 24 Nov 2016 18:52:04 +0100
|
|
Adam Williamson |
4c60d7 |
Subject: [PATCH] core: make sure initrd-switch-root command survives PID1's
|
|
Adam Williamson |
4c60d7 |
killing spree (#4730)
|
|
Adam Williamson |
4c60d7 |
|
|
Adam Williamson |
4c60d7 |
This is a different way to implement the fix proposed by commit
|
|
Adam Williamson |
4c60d7 |
a4021390fef27f4136497328f suggested by Lennart Poettering.
|
|
Adam Williamson |
4c60d7 |
|
|
Adam Williamson |
4c60d7 |
In this patch we instruct PID1 to not kill "systemctl switch-root" command
|
|
Adam Williamson |
4c60d7 |
started by initrd-switch-root service using the "argv[0][0]='@'" trick.
|
|
Adam Williamson |
4c60d7 |
|
|
Adam Williamson |
4c60d7 |
See: https://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons/ for
|
|
Adam Williamson |
4c60d7 |
more details.
|
|
Adam Williamson |
4c60d7 |
|
|
Adam Williamson |
4c60d7 |
We had to backup argv[0] because argv is modified by dispatch_verb().
|
|
Adam Williamson |
4c60d7 |
---
|
|
Adam Williamson |
4c60d7 |
src/systemctl/systemctl.c | 10 ++++++++++
|
|
Adam Williamson |
4c60d7 |
1 files changed, 10 insertions(+), 0 deletions(-)
|
|
Adam Williamson |
4c60d7 |
|
|
Adam Williamson |
4c60d7 |
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
|
|
Adam Williamson |
4c60d7 |
index 4fd8d7ba2..ed1c7178b 100644
|
|
Adam Williamson |
4c60d7 |
--- a/src/systemctl/systemctl.c
|
|
Adam Williamson |
4c60d7 |
+++ b/src/systemctl/systemctl.c
|
|
Adam Williamson |
4c60d7 |
@@ -142,6 +142,7 @@ static const char *arg_kill_who = NULL;
|
|
Adam Williamson |
4c60d7 |
static int arg_signal = SIGTERM;
|
|
Adam Williamson |
4c60d7 |
static char *arg_root = NULL;
|
|
Adam Williamson |
4c60d7 |
static usec_t arg_when = 0;
|
|
Adam Williamson |
4c60d7 |
+static char *argv_cmdline = NULL;
|
|
Adam Williamson |
4c60d7 |
static enum action {
|
|
Adam Williamson |
4c60d7 |
_ACTION_INVALID,
|
|
Adam Williamson |
4c60d7 |
ACTION_SYSTEMCTL,
|
|
Adam Williamson |
4c60d7 |
@@ -5638,6 +5639,13 @@ static int switch_root(int argc, char *argv[], void *userdata) {
|
|
Adam Williamson |
4c60d7 |
init = NULL;
|
|
Adam Williamson |
4c60d7 |
}
|
|
Adam Williamson |
4c60d7 |
|
|
Adam Williamson |
4c60d7 |
+ /* Instruct PID1 to exclude us from its killing spree applied during
|
|
Adam Williamson |
4c60d7 |
+ * the transition from the initrd to the main system otherwise we would
|
|
Adam Williamson |
4c60d7 |
+ * exit with a failure status even though the switch to the new root
|
|
Adam Williamson |
4c60d7 |
+ * has succeed. */
|
|
Adam Williamson |
4c60d7 |
+ if (in_initrd())
|
|
Adam Williamson |
4c60d7 |
+ argv_cmdline[0] = '@';
|
|
Adam Williamson |
4c60d7 |
+
|
|
Adam Williamson |
4c60d7 |
r = acquire_bus(BUS_MANAGER, &bus;;
|
|
Adam Williamson |
4c60d7 |
if (r < 0)
|
|
Adam Williamson |
4c60d7 |
return r;
|
|
Adam Williamson |
4c60d7 |
@@ -8373,6 +8381,8 @@ static int logind_cancel_shutdown(void) {
|
|
Adam Williamson |
4c60d7 |
int main(int argc, char*argv[]) {
|
|
Adam Williamson |
4c60d7 |
int r;
|
|
Adam Williamson |
4c60d7 |
|
|
Adam Williamson |
4c60d7 |
+ argv_cmdline = argv[0];
|
|
Adam Williamson |
4c60d7 |
+
|
|
Adam Williamson |
4c60d7 |
setlocale(LC_ALL, "");
|
|
Adam Williamson |
4c60d7 |
log_parse_environment();
|
|
Adam Williamson |
4c60d7 |
log_open();
|
|
Adam Williamson |
4c60d7 |
--
|
|
Adam Williamson |
4c60d7 |
2.11.0
|
|
Adam Williamson |
4c60d7 |
|