-
-/*
- * signals.c -- general signals interface for nmh
- *
- * $Id$
+/* 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
#include <h/mh.h>
#include <h/signals.h>
-
-
-int
-SIGPROCMASK (int how, const sigset_t *set, sigset_t *oset)
-{
-#ifdef POSIX_SIGNALS
- return sigprocmask(how, set, oset);
-#else
-# ifdef BSD_SIGNALS
- switch(how) {
- case SIG_BLOCK:
- *oset = sigblock(*set);
- break;
- case SIG_UNBLOCK:
- sigfillset(*oset);
- *oset = sigsetmask(*oset);
- sigsetmask(*oset & ~(*set));
- break;
- case SIG_SETMASK:
- *oset = sigsetmask(*set);
- break;
- default:
- adios(NULL, "unknown flag in SIGPROCMASK");
- break;
- }
- return 0;
-# endif
-#endif
-}
+#include "m_mktemp.h"
/*
* signals, if the machine supports them. Also, (assuming
* OS support), it restarts interrupted system calls for all
* signals except SIGALRM.
+ *
+ * Since we are now assuming POSIX signal support everywhere, we always
+ * use reliable signals.
*/
SIGNAL_HANDLER
SIGNAL (int sig, SIGNAL_HANDLER func)
{
-#ifdef POSIX_SIGNALS
struct sigaction act, oact;
act.sa_handler = func;
# endif
}
if (sigaction(sig, &act, &oact) < 0)
- return (SIG_ERR);
- return (oact.sa_handler);
-#else
- return signal (sig, func);
-#endif
+ return SIG_ERR;
+ return oact.sa_handler;
}
SIGNAL_HANDLER
SIGNAL2 (int sig, SIGNAL_HANDLER func)
{
-#ifdef POSIX_SIGNALS
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);
# endif
}
if (sigaction(sig, &act, &oact) < 0)
- return (SIG_ERR);
+ return SIG_ERR;
}
- return (oact.sa_handler);
-#else
- SIGNAL_HANDLER ofunc;
-
- if ((ofunc = signal (sig, SIG_IGN)) != SIG_IGN)
- signal (sig, func);
- return ofunc;
-#endif
+ 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;
+}