]> diplodocus.org Git - nmh/blobdiff - sbr/signals.c
h/prototypes.h: Remove mhlsbr() prototype; no such function.
[nmh] / sbr / signals.c
index eb26e632317be1075936a8981f8fe5a17c90ec71..36ba9d02ebf4eae8002bf884a8c8c0b2b9a51ffb 100644 (file)
@@ -1,14 +1,13 @@
-
-/*
- * signals.c -- general signals interface for nmh
+/* signals.c -- general signals interface for nmh
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/signals.h>
+#include "h/mh.h"
+#include "h/signals.h"
+#include "m_mktemp.h"
 
 
 /*
@@ -40,8 +39,8 @@ SIGNAL (int sig, SIGNAL_HANDLER func)
 # endif
     }
     if (sigaction(sig, &act, &oact) < 0)
-       return (SIG_ERR);
-    return (oact.sa_handler);
+       return SIG_ERR;
+    return oact.sa_handler;
 }
 
 
@@ -57,7 +56,7 @@ SIGNAL2 (int sig, SIGNAL_HANDLER func)
     struct sigaction act, oact;
 
     if (sigaction(sig, NULL, &oact) < 0)
-       return (SIG_ERR);
+       return SIG_ERR;
     if (oact.sa_handler != SIG_IGN) {
        act.sa_handler = func;
        sigemptyset(&act.sa_mask);
@@ -73,8 +72,36 @@ SIGNAL2 (int sig, SIGNAL_HANDLER func)
 # endif
        }
        if (sigaction(sig, &act, &oact) < 0)
-           return (SIG_ERR);
+           return SIG_ERR;
     }
-    return (oact.sa_handler);
+    return oact.sa_handler;
 }
 
+
+/*
+ * For use by nmh_init().
+ */
+int
+setup_signal_handlers(void)
+{
+    /*
+     * Catch HUP, INT, QUIT, and TERM so that we can clean up tmp
+     * files when the user terminates the process early.  And also a
+     * few other common signals that can be thrown due to bugs, stack
+     * overflow, etc.
+     */
+
+    if (SIGNAL(SIGHUP,  remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGINT,  remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGQUIT, remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGTERM, remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGILL,  remove_registered_files) == SIG_ERR  ||
+#       ifdef SIGBUS
+        SIGNAL(SIGBUS,  remove_registered_files) == SIG_ERR  ||
+#       endif
+        SIGNAL(SIGSEGV, remove_registered_files) == SIG_ERR) {
+        return NOTOK;
+    }
+
+    return OK;
+}