chiark / gitweb /
Reset signal-mask on re-exec to init=..
authorRuediger Oertel <ro@suse.de>
Fri, 13 Jun 2014 14:41:06 +0000 (16:41 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 16 Jun 2014 13:23:17 +0000 (15:23 +0200)
Process 1 (aka init) needs to be started with an empty signal mask.
That includes the process 1 that's started after the initrd is finished.
When the initrd is using systemd (as it does with dracut based initrds)
then it is systemd that calls the real init.  Normally this is systemd
again, except when the user uses for instance "init=/bin/bash" on the
kernel command line.

src/core/main.c

index 3aac5d1d97fe281e097864cd543968c84f50ca9e..3e57f07c422dafd17f8b0535feb0a9671a8741f8 100644 (file)
@@ -1843,6 +1843,7 @@ finish:
         if (reexecute) {
                 const char **args;
                 unsigned i, args_size;
+                sigset_t ss, o_ss;
 
                 /* Close and disarm the watchdog, so that the new
                  * instance can reinitialize it, but doesn't get
@@ -1926,6 +1927,11 @@ finish:
                 args[i++] = NULL;
                 assert(i <= args_size);
 
+                /* reenable any blocked signals, especially important
+                 * if we switch from initial ramdisk to init=... */
+                sigemptyset(&ss);
+                sigprocmask(SIG_SETMASK, &ss, &o_ss);
+
                 if (switch_root_init) {
                         args[0] = switch_root_init;
                         execv(args[0], (char* const*) args);
@@ -1944,6 +1950,8 @@ finish:
                         log_error("Failed to execute /bin/sh, giving up: %m");
                 } else
                         log_warning("Failed to execute /sbin/init, giving up: %m");
+
+                sigprocmask(SIG_SETMASK, &o_ss, NULL);
         }
 
         if (arg_serialization) {