X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/f475d48680eb8bb0b6543efab9057eba2773666e..e6c91771:/sbr/signals.c?ds=inline diff --git a/sbr/signals.c b/sbr/signals.c index eb26e632..accb6950 100644 --- a/sbr/signals.c +++ b/sbr/signals.c @@ -1,6 +1,4 @@ - -/* - * 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 @@ -9,6 +7,7 @@ #include #include +#include "m_mktemp.h" /* @@ -78,3 +77,30 @@ SIGNAL2 (int sig, SIGNAL_HANDLER func) 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; +}