X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fsignals.c;h=5b55fc429c21871a1a24d7d16e72b5f53a694f06;hp=9f5f3792c93dd295db4c9e64061f2458f2380e64;hb=5cb46b33551f28e4168989e752e09bd927e993f9;hpb=6c42153ad9362cc676ea66563bf400d7511b3b68 diff --git a/sbr/signals.c b/sbr/signals.c index 9f5f379..5b55fc4 100644 --- a/sbr/signals.c +++ b/sbr/signals.c @@ -1,120 +1,78 @@ - /* - * signals.c -- general signals interface for nmh - * - * $Id$ - * - * 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. - */ +** 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 #include -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 -} - - /* - * A version of the function `signal' that uses reliable - * signals, if the machine supports them. Also, (assuming - * OS support), it restarts interrupted system calls for all - * signals except SIGALRM. - */ +** A version of the function `signal' that uses reliable +** 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) +SIGNAL(int sig, SIGNAL_HANDLER func) { -#ifdef POSIX_SIGNALS - struct sigaction act, oact; + struct sigaction act, oact; - act.sa_handler = func; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; + act.sa_handler = func; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; - if (sig == SIGALRM) { + if (sig == SIGALRM) { # ifdef SA_INTERRUPT - act.sa_flags |= SA_INTERRUPT; /* SunOS */ + act.sa_flags |= SA_INTERRUPT; /* SunOS */ # endif - } else { + } else { # ifdef SA_RESTART - act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ + act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ # endif - } - if (sigaction(sig, &act, &oact) < 0) - return (SIG_ERR); - return (oact.sa_handler); -#else - return signal (sig, func); -#endif + } + if (sigaction(sig, &act, &oact) < 0) + return (SIG_ERR); + return (oact.sa_handler); } /* - * A version of the function `signal' that will set - * the handler of `sig' to `func' if the signal is - * not currently set to SIG_IGN. Also uses reliable - * signals if available. - */ +** A version of the function `signal' that will set +** the handler of `sig' to `func' if the signal is +** not currently set to SIG_IGN. Also uses reliable +** signals if available. +*/ SIGNAL_HANDLER -SIGNAL2 (int sig, SIGNAL_HANDLER func) +SIGNAL2(int sig, SIGNAL_HANDLER func) { -#ifdef POSIX_SIGNALS - struct sigaction act, oact; + struct sigaction act, oact; - if (sigaction(sig, NULL, &oact) < 0) - return (SIG_ERR); - if (oact.sa_handler != SIG_IGN) { - act.sa_handler = func; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; + if (sigaction(sig, NULL, &oact) < 0) + return (SIG_ERR); + if (oact.sa_handler != SIG_IGN) { + act.sa_handler = func; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; - if (sig == SIGALRM) { + if (sig == SIGALRM) { # ifdef SA_INTERRUPT - act.sa_flags |= SA_INTERRUPT; /* SunOS */ + act.sa_flags |= SA_INTERRUPT; /* SunOS */ # endif - } else { + } else { # ifdef SA_RESTART - act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ + act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ # endif + } + if (sigaction(sig, &act, &oact) < 0) + return (SIG_ERR); } - if (sigaction(sig, &act, &oact) < 0) - 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); } -