chiark / gitweb /
main: expclitly ignore signal when executing crash shell
[elogind.git] / main.c
diff --git a/main.c b/main.c
index 0eb64d265928e918b61e0797ebd825ed0b365ae6..622ba631519b90811d92e8aae79d9c15acf5514f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -110,9 +110,19 @@ _noreturn static void crash(int sig) {
                 chvt(crash_chvt);
 
         if (crash_shell) {
+                sigset_t mask;
+
                 log_info("Executing crash shell in 10s...");
                 sleep(10);
 
+                /* Make sure the signal is not delivered inside the
+                 * exec() */
+                assert_se(sigemptyset(&mask) == 0);
+                assert_se(sigaddset(&mask, sig) == 0);
+                assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
+
+                ignore_signal(sig);
+
                 execl("/bin/sh", "/bin/sh", NULL);
                 log_error("execl() failed: %s", strerror(errno));
         }
@@ -445,8 +455,8 @@ int main(int argc, char *argv[]) {
         assert_se(reset_all_signal_handlers() == 0);
 
         /* If we are init, we can block sigkill. Yay. */
-        signal(SIGKILL, SIG_IGN);
-        signal(SIGPIPE, SIG_IGN);
+        ignore_signal(SIGKILL);
+        ignore_signal(SIGPIPE);
 
         /* Close all open files */
         assert_se(close_all_fds(NULL, 0) == 0);
@@ -567,5 +577,8 @@ finish:
 
         dbus_shutdown();
 
+        if (getpid() == 1)
+                freeze();
+
         return retval;
 }