X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/6e2695e9e0518960a90af1bc74bea4938259ac8c..309ca62193772fd8ba532fd413b51a61be0c741e:/setsignal.c diff --git a/setsignal.c b/setsignal.c index 5269a7f1..a4b59cef 100644 --- a/setsignal.c +++ b/setsignal.c @@ -20,15 +20,15 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/setsignal.c,v 1.7 2000-07-11 00:49:03 assar Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/setsignal.c,v 1.11 2003-11-16 09:36:42 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #ifdef HAVE_SIGACTION @@ -42,15 +42,33 @@ static const char rcsid[] = #include "setsignal.h" /* - * An os independent signal() with BSD semantics, e.g. the signal - * catcher is restored following service of the signal. + * An OS-independent signal() with, whenever possible, partial BSD + * semantics, i.e. the signal handler is restored following service + * of the signal, but system calls are *not* restarted, so that if + * "pcap_breakloop()" is called in a signal handler in a live capture, + * the read/recvfrom/whatever in the live capture doesn't get restarted, + * it returns -1 and sets "errno" to EINTR, so we can break out of the + * live capture loop. * - * When sigset() is available, signal() has SYSV semantics and sigset() - * has BSD semantics and call interface. Unfortunately, Linux does not - * have sigset() so we use the more complicated sigaction() interface - * there. + * We use "sigaction()" if available. We don't specify that the signal + * should restart system calls, so that should always do what we want. * - * Did I mention that signals suck? + * Otherwise, if "sigset()" is available, it probably has BSD semantics + * while "signal()" has traditional semantics, so we use "sigset()"; it + * might cause system calls to be restarted for the signal, however. + * I don't know whether, in any systems where it did cause system calls to + * be restarted, there was a way to ask it not to do so; there may no + * longer be any interesting systems without "sigaction()", however, + * and, if there are, they might have "sigvec()" with SV_INTERRUPT + * (which I think first appeared in 4.3BSD). + * + * Otherwise, we use "signal()" - which means we might get traditional + * semantics, wherein system calls don't get restarted *but* the + * signal handler is reset to SIG_DFL and the signal is not blocked, + * so that a subsequent signal would kill the process immediately. + * + * Did I mention that signals suck? At least in POSIX-compliant systems + * they suck far less, as those systems have "sigaction()". */ RETSIGTYPE (*setsignal (int sig, RETSIGTYPE (*func)(int)))(int) @@ -60,9 +78,6 @@ RETSIGTYPE memset(&new, 0, sizeof(new)); new.sa_handler = func; -#ifdef SA_RESTART - new.sa_flags |= SA_RESTART; -#endif if (sigaction(sig, &new, &old) < 0) return (SIG_ERR); return (old.sa_handler);