5509c00
From ab25a485218194a432a8238b772005f4506059f3 Mon Sep 17 00:00:00 2001
5509c00
From: Ruediger Oertel <ro@suse.de>
5509c00
Date: Fri, 13 Jun 2014 16:41:06 +0200
5509c00
Subject: [PATCH] Reset signal-mask on re-exec to init=..
5509c00
5509c00
Process 1 (aka init) needs to be started with an empty signal mask.
5509c00
That includes the process 1 that's started after the initrd is finished.
5509c00
When the initrd is using systemd (as it does with dracut based initrds)
5509c00
then it is systemd that calls the real init.  Normally this is systemd
5509c00
again, except when the user uses for instance "init=/bin/bash" on the
5509c00
kernel command line.
5509c00
5509c00
(cherry picked from commit 5a85ca1cb622fda4a39c8a6f00dccea7f8a1e82a)
5509c00
---
5509c00
 src/core/main.c | 8 ++++++++
5509c00
 1 file changed, 8 insertions(+)
5509c00
5509c00
diff --git a/src/core/main.c b/src/core/main.c
5509c00
index d5d1ee2b..e87b8cc8 100644
5509c00
--- a/src/core/main.c
5509c00
+++ b/src/core/main.c
5509c00
@@ -1831,6 +1831,7 @@ finish:
5509c00
         if (reexecute) {
5509c00
                 const char **args;
5509c00
                 unsigned i, args_size;
5509c00
+                sigset_t ss, o_ss;
5509c00
 
5509c00
                 /* Close and disarm the watchdog, so that the new
5509c00
                  * instance can reinitialize it, but doesn't get
5509c00
@@ -1914,6 +1915,11 @@ finish:
5509c00
                 args[i++] = NULL;
5509c00
                 assert(i <= args_size);
5509c00
 
5509c00
+                /* reenable any blocked signals, especially important
5509c00
+                 * if we switch from initial ramdisk to init=... */
5509c00
+                sigemptyset(&ss);
5509c00
+                sigprocmask(SIG_SETMASK, &ss, &o_ss);
5509c00
+
5509c00
                 if (switch_root_init) {
5509c00
                         args[0] = switch_root_init;
5509c00
                         execv(args[0], (char* const*) args);
5509c00
@@ -1932,6 +1938,8 @@ finish:
5509c00
                         log_error("Failed to execute /bin/sh, giving up: %m");
5509c00
                 } else
5509c00
                         log_warning("Failed to execute /sbin/init, giving up: %m");
5509c00
+
5509c00
+                sigprocmask(SIG_SETMASK, &o_ss, NULL);
5509c00
         }
5509c00
 
5509c00
         if (arg_serialization) {