chiark / gitweb /
manager: we are not interested in SIGPIPE/SIGTTIN
[elogind.git] / main.c
diff --git a/main.c b/main.c
index 5f0aeba85752c09293120fccd3e2da72f41f9322..7dbcc90d5ebff9ae9695883782af49ddb7777975 100644 (file)
--- a/main.c
+++ b/main.c
@@ -48,7 +48,8 @@ static char *default_unit = NULL;
 static ManagerRunningAs running_as = _MANAGER_RUNNING_AS_INVALID;
 
 static bool dump_core = true;
-static bool crash_shell = true;
+static bool crash_shell = false;
+static int crash_chvt = -1;
 
 _noreturn static void freeze(void) {
         for (;;)
@@ -102,6 +103,9 @@ _noreturn static void crash(int sig) {
                 }
         }
 
+        if (crash_chvt)
+                chvt(crash_chvt);
+
         if (crash_shell) {
                 log_info("Executing crash shell in 10s...");
                 sleep(10);
@@ -123,6 +127,10 @@ static void install_crash_handler(void) {
         sa.sa_flags = SA_NODEFER;
 
         assert_se(sigaction(SIGSEGV, &sa, NULL) == 0);
+        assert_se(sigaction(SIGILL, &sa, NULL) == 0);
+        assert_se(sigaction(SIGFPE, &sa, NULL) == 0);
+        assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
+        assert_se(sigaction(SIGQUIT, &sa, NULL) == 0);
         assert_se(sigaction(SIGABRT, &sa, NULL) == 0);
 }
 
@@ -170,7 +178,7 @@ static int parse_proc_cmdline_word(const char *word) {
                 int r;
 
                 if ((r = parse_boolean(word + 18)) < 0)
-                        log_warning("Failed to parse dump core switch %s, Ignoring", word + 18);
+                        log_warning("Failed to parse dump core switch %s, Ignoring.", word + 18);
                 else
                         dump_core = r;
 
@@ -178,10 +186,18 @@ static int parse_proc_cmdline_word(const char *word) {
                 int r;
 
                 if ((r = parse_boolean(word + 20)) < 0)
-                        log_warning("Failed to parse crash shell switch %s, Ignoring", word + 20);
+                        log_warning("Failed to parse crash shell switch %s, Ignoring.", word + 20);
                 else
                         crash_shell = r;
 
+        } else if (startswith(word, "systemd.crash_chvt=")) {
+                int k;
+
+                if (safe_atoi(word + 19, &k) < 0)
+                        log_warning("Failed to parse crash chvt switch %s, Ignoring.", word + 19);
+                else
+                        crash_chvt = k;
+
         } else if (startswith(word, "systemd.")) {
 
                 log_warning("Unknown kernel switch %s. Ignoring.", word);
@@ -192,6 +208,7 @@ static int parse_proc_cmdline_word(const char *word) {
                 log_info("systemd.log_level=LEVEL                  Log level");
                 log_info("systemd.dump_core=0|1                    Dump core on crash");
                 log_info("systemd.crash_shell=0|1                  On crash run shell");
+                log_info("systemd.crash_chvt=N                     Change to VT #N on crash");
 
         } else {
                 unsigned i;
@@ -370,6 +387,10 @@ int main(int argc, char *argv[]) {
         /* Reset all signal handlers. */
         assert_se(reset_all_signal_handlers() == 0);
 
+        /* If we are init, we can block sigkill. Yay. */
+        signal(SIGKILL, SIG_IGN);
+        signal(SIGPIPE, SIG_IGN);
+
         /* Close all open files */
         assert_se(close_all_fds(NULL, 0) == 0);
 
@@ -414,7 +435,8 @@ int main(int argc, char *argv[]) {
         log_open_syslog();
         log_open_kmsg();
 
-        /* Make sure we leave a core dump */
+        /* Make sure we leave a core dump without panicing the
+         * kernel. */
         if (getpid() == 1)
                 install_crash_handler();