diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-10-15 22:36:07 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-10-15 22:36:07 -0700 |
commit | fdd0467bcd46ea0d472111adedd21f43d6d4d15e (patch) | |
tree | 93089bc833fbb7784d51cd44ef5d762b35b10a7b | |
parent | 88d1467627bbe0fbe2e52098aa099ef0319ac713 (diff) | |
download | tcpdump-fdd0467bcd46ea0d472111adedd21f43d6d4d15e.tar.gz |
On UN*X, always use sigaction(), and always have signal handlers return void.
Some time between the mid 1980's and 1990 called; they want their
old-fashioned UNIX signal handling back. ANSI C has had signal handlers
returning void sincer, well, 1989, and POSIX has had sigaction() since
close to forever. No need to worry about really old UN*Xes here.
On Windows, it's also void (as per ANSI C); use signal().
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | aclocal.m4 | 35 | ||||
-rw-r--r-- | addrtoname.c | 1 | ||||
-rw-r--r-- | config.h.in | 15 | ||||
-rwxr-xr-x | configure | 79 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | netdissect-stdinc.h | 1 | ||||
-rw-r--r-- | setsignal.c | 90 | ||||
-rw-r--r-- | setsignal.h | 25 | ||||
-rw-r--r-- | tcpdump.c | 37 |
10 files changed, 30 insertions, 258 deletions
diff --git a/Makefile.in b/Makefile.in index 0941f0e5..99f6dbaf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -70,7 +70,7 @@ DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@ @rm -f $@ $(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c -CSRC = setsignal.c tcpdump.c +CSRC = tcpdump.c LIBNETDISSECT_SRC=\ addrtoname.c \ @@ -290,7 +290,6 @@ HDR = \ rpc_auth.h \ rpc_msg.h \ rpl.h \ - setsignal.h \ signature.h \ slcompress.h \ smb.h \ @@ -668,41 +668,6 @@ reproduce this problem ourselves.]) ]) dnl -dnl Define RETSIGTYPE and RETSIGVAL -dnl -dnl usage: -dnl -dnl AC_LBL_TYPE_SIGNAL -dnl -dnl results: -dnl -dnl RETSIGTYPE (defined) -dnl RETSIGVAL (defined) -dnl -AC_DEFUN(AC_LBL_TYPE_SIGNAL, - [AC_BEFORE([$0], [AC_LBL_LIBPCAP]) - AC_TYPE_SIGNAL - if test "$ac_cv_type_signal" = void ; then - AC_DEFINE(RETSIGVAL,[],[return value of signal handlers]) - else - AC_DEFINE(RETSIGVAL,(0),[return value of signal handlers]) - fi - case "$host_os" in - - irix*) - AC_DEFINE(_BSD_SIGNALS,1,[get BSD semantics on Irix]) - ;; - - *) - dnl prefer sigaction() to sigset() - AC_CHECK_FUNCS(sigaction) - if test $ac_cv_func_sigaction = no ; then - AC_CHECK_FUNCS(sigset) - fi - ;; - esac]) - -dnl dnl If using gcc, make sure we have ANSI ioctl definitions dnl dnl usage: diff --git a/addrtoname.c b/addrtoname.c index fe6338d5..01e33093 100644 --- a/addrtoname.c +++ b/addrtoname.c @@ -67,7 +67,6 @@ extern int ether_ntohost(char *, const struct ether_addr *); #include "addrtostr.h" #include "ethertype.h" #include "llc.h" -#include "setsignal.h" #include "extract.h" #include "oui.h" diff --git a/config.h.in b/config.h.in index 558ab41f..487364dc 100644 --- a/config.h.in +++ b/config.h.in @@ -187,12 +187,6 @@ /* Define to 1 if you have the `setlinebuf' function. */ #undef HAVE_SETLINEBUF -/* Define to 1 if you have the `sigaction' function. */ -#undef HAVE_SIGACTION - -/* Define to 1 if you have the `sigset' function. */ -#undef HAVE_SIGSET - /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF @@ -280,12 +274,6 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION -/* Define as the return type of signal handlers (`int' or `void'). */ -#undef RETSIGTYPE - -/* return value of signal handlers */ -#undef RETSIGVAL - /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS @@ -304,9 +292,6 @@ /* define if should drop privileges by default */ #undef WITH_USER -/* get BSD semantics on Irix */ -#undef _BSD_SIGNALS - /* define on AIX to get certain functions */ #undef _SUN @@ -5102,85 +5102,6 @@ esac fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking return type of signal handlers" >&5 -$as_echo_n "checking return type of signal handlers... " >&6; } -if ${ac_cv_type_signal+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <sys/types.h> -#include <signal.h> - -int -main () -{ -return *(signal (0, 0)) (0) == 1; - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_type_signal=int -else - ac_cv_type_signal=void -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_signal" >&5 -$as_echo "$ac_cv_type_signal" >&6; } - -cat >>confdefs.h <<_ACEOF -#define RETSIGTYPE $ac_cv_type_signal -_ACEOF - - - if test "$ac_cv_type_signal" = void ; then - -$as_echo "#define RETSIGVAL /**/" >>confdefs.h - - else - -$as_echo "#define RETSIGVAL (0)" >>confdefs.h - - fi - case "$host_os" in - - irix*) - -$as_echo "#define _BSD_SIGNALS 1" >>confdefs.h - - ;; - - *) - for ac_func in sigaction -do : - ac_fn_c_check_func "$LINENO" "sigaction" "ac_cv_func_sigaction" -if test "x$ac_cv_func_sigaction" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_SIGACTION 1 -_ACEOF - -fi -done - - if test $ac_cv_func_sigaction = no ; then - for ac_func in sigset -do : - ac_fn_c_check_func "$LINENO" "sigset" "ac_cv_func_sigset" -if test "x$ac_cv_func_sigset" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_SIGSET 1 -_ACEOF - -fi -done - - fi - ;; - esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dnet_htoa" >&5 $as_echo_n "checking for library containing dnet_htoa... " >&6; } if ${ac_cv_search_dnet_htoa+:} false; then : diff --git a/configure.in b/configure.in index f8a78d26..654d973a 100644 --- a/configure.in +++ b/configure.in @@ -412,8 +412,6 @@ if test $needsnprintf = yes; then AC_LIBOBJ(snprintf) fi -AC_LBL_TYPE_SIGNAL - AC_SEARCH_LIBS(dnet_htoa, dnet, AC_DEFINE(HAVE_DNET_HTOA, 1, [define if you have the dnet_htoa function])) diff --git a/netdissect-stdinc.h b/netdissect-stdinc.h index 343e13c0..d66a9f02 100644 --- a/netdissect-stdinc.h +++ b/netdissect-stdinc.h @@ -215,7 +215,6 @@ typedef char* caddr_t; #define MAXHOSTNAMELEN 64 #define snprintf _snprintf #define vsnprintf _vsnprintf -#define RETSIGTYPE void #else /* _WIN32 */ diff --git a/setsignal.c b/setsignal.c deleted file mode 100644 index 4d93cebf..00000000 --- a/setsignal.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1997 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that: (1) source code distributions - * retain the above copyright notice and this paragraph in its entirety, (2) - * distributions including binary code include the above copyright notice and - * this paragraph in its entirety in the documentation or other materials - * provided with the distribution, and (3) all advertising materials mentioning - * features or use of this software display the following acknowledgement: - * ``This product includes software developed by the University of California, - * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of - * the University nor the names of its contributors may be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <netdissect-stdinc.h> - -#include <signal.h> -#ifdef HAVE_SIGACTION -#include <string.h> -#endif - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "setsignal.h" - -/* - * 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. - * - * We use "sigaction()" if available. We don't specify that the signal - * should restart system calls, so that should always do what we want. - * - * 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) -{ -#ifdef HAVE_SIGACTION - struct sigaction old, new; - - memset(&new, 0, sizeof(new)); - new.sa_handler = func; - if (sig == SIGCHLD) - new.sa_flags = SA_RESTART; - if (sigaction(sig, &new, &old) < 0) - return (SIG_ERR); - return (old.sa_handler); - -#else -#ifdef HAVE_SIGSET - return (sigset(sig, func)); -#else - return (signal(sig, func)); -#endif -#endif -} - diff --git a/setsignal.h b/setsignal.h deleted file mode 100644 index 91a2048a..00000000 --- a/setsignal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1997 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that: (1) source code distributions - * retain the above copyright notice and this paragraph in its entirety, (2) - * distributions including binary code include the above copyright notice and - * this paragraph in its entirety in the documentation or other materials - * provided with the distribution, and (3) all advertising materials mentioning - * features or use of this software display the following acknowledgement: - * ``This product includes software developed by the University of California, - * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of - * the University nor the names of its contributors may be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ -#ifndef setsignal_h -#define setsignal_h - -RETSIGTYPE (*setsignal(int, RETSIGTYPE (*)(int)))(int); -#endif @@ -122,7 +122,6 @@ The Regents of the University of California. All rights reserved.\n"; #include "interface.h" #include "addrtoname.h" #include "machdep.h" -#include "setsignal.h" #include "gmt2local.h" #include "pcap-missing.h" #include "ascii_strcasecmp.h" @@ -192,8 +191,9 @@ cap_channel_t *capdns; static NORETURN void error(FORMAT_STRING(const char *), ...) PRINTFLIKE(1, 2); static void warning(FORMAT_STRING(const char *), ...) PRINTFLIKE(1, 2); static NORETURN void exit_tcpdump(int); -static RETSIGTYPE cleanup(int); -static RETSIGTYPE child_cleanup(int); +static void (*setsignal (int sig, void (*func)(int)))(int); +static void cleanup(int); +static void child_cleanup(int); static void print_version(void); static void print_usage(void); static NORETURN void show_tstamp_types_and_exit(pcap_t *, const char *device); @@ -208,7 +208,7 @@ static void dump_packet(u_char *, const struct pcap_pkthdr *, const u_char *); static void droproot(const char *, const char *); #ifdef SIGNAL_REQ_INFO -RETSIGTYPE requestinfo(int); +void requestinfo(int); #endif #if defined(USE_WIN32_MM_TIMER) @@ -1191,7 +1191,7 @@ main(int argc, char **argv) const char *dlt_name; struct bpf_program fcode; #ifndef _WIN32 - RETSIGTYPE (*oldhandler)(int); + void (*oldhandler)(int); #endif struct dump_info dumpinfo; u_char *pcap_userdata; @@ -2251,8 +2251,29 @@ main(int argc, char **argv) exit_tcpdump(status == -1 ? 1 : 0); } +/* + * Catch a signal. + */ +static void +(*setsignal (int sig, void (*func)(int)))(int) +{ +#ifdef _WIN32 + return (signal(sig, func)); +#else + struct sigaction old, new; + + memset(&new, 0, sizeof(new)); + new.sa_handler = func; + if (sig == SIGCHLD) + new.sa_flags = SA_RESTART; + if (sigaction(sig, &new, &old) < 0) + return (SIG_ERR); + return (old.sa_handler); +#endif +} + /* make a clean exit on interrupts */ -static RETSIGTYPE +static void cleanup(int signo _U_) { #ifdef USE_WIN32_MM_TIMER @@ -2297,7 +2318,7 @@ cleanup(int signo _U_) waiting a child processes to die */ #if defined(HAVE_FORK) || defined(HAVE_VFORK) -static RETSIGTYPE +static void child_cleanup(int signo _U_) { wait(NULL); @@ -2684,7 +2705,7 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) #endif #ifdef SIGNAL_REQ_INFO -RETSIGTYPE requestinfo(int signo _U_) +void requestinfo(int signo _U_) { if (infodelay) ++infoprint; |