]> The Tcpdump Group git mirrors - tcpdump/commitdiff
On UN*X, always use sigaction(), and always have signal handlers return void.
authorGuy Harris <[email protected]>
Mon, 16 Oct 2017 05:36:07 +0000 (22:36 -0700)
committerGuy Harris <[email protected]>
Mon, 16 Oct 2017 05:36:07 +0000 (22:36 -0700)
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().

Makefile.in
aclocal.m4
addrtoname.c
config.h.in
configure
configure.in
netdissect-stdinc.h
setsignal.c [deleted file]
setsignal.h [deleted file]
tcpdump.c

index 0941f0e5078fb3470569650b764057097d672afe..99f6dbafd25105c2ee681427242ed619883d38f5 100644 (file)
@@ -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 \
index 7b61d27c9555b538d67fdbf8911608159c08b51a..fbfbbea18feacd7c6b03140d36a9d8893093842f 100644 (file)
@@ -667,41 +667,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
index fe6338d5a45602b700f94087dba1689eea06b808..01e330933b0c00a758d54d61796878a91ab2af25 100644 (file)
@@ -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"
 
index 558ab41ff4c4f5bebd3efcef7ab8bca8cbf2d623..487364dcc1c6e22a615a27a8eb8b28b2c30765b9 100644 (file)
 /* 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
 
 /* 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
 
 /* 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
 
index 6e98d577080b18cdd5b9592a5a0780b1aa5a5e34..e359c868bd162b21256c04f728d04cf01cab6c8c 100755 (executable)
--- a/configure
+++ b/configure
@@ -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 :
index f8a78d267ec1280d3e643c79241a357e40cc79a2..654d973aa2d26c5ff854fbfaae2e80232287f2c4 100644 (file)
@@ -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]))
 
index 343e13c0e5afd9b9b1b26faac53abccea52ab623..d66a9f02500615fb0531087d6cf627bd420a4f15 100644 (file)
@@ -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 (file)
index 4d93ceb..0000000
+++ /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 (file)
index 91a2048..0000000
+++ /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
index 7512e37bad6c0ac5be17e0a71c691f6b1015d7fa..65b7e76950a0fcb58b795f26652bba265309968b 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -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;