From 9ae4abf6fca2a6417dfff8fd0fb8ac10a47c2a4c Mon Sep 17 00:00:00 2001 From: guenther Date: Wed, 14 Oct 2015 04:55:17 +0000 Subject: [PATCH] Remove conditional compilation and #defines around signal handling Don't catch signals that were ignored on entry Suppress SIGCHLD if our kid is stopped: we don't care and it's not an error ok millert@ --- usr.sbin/tcpdump/Makefile | 4 +-- usr.sbin/tcpdump/setsignal.c | 55 +++++++++--------------------------- usr.sbin/tcpdump/setsignal.h | 6 ++-- usr.sbin/tcpdump/tcpdump.c | 18 ++++-------- 4 files changed, 24 insertions(+), 59 deletions(-) diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile index 0a50b6c4f17..78c4ffed576 100644 --- a/usr.sbin/tcpdump/Makefile +++ b/usr.sbin/tcpdump/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.58 2015/10/13 14:36:15 stsp Exp $ +# $OpenBSD: Makefile,v 1.59 2015/10/14 04:55:17 guenther Exp $ # # Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 # The Regents of the University of California. All rights reserved. @@ -28,7 +28,7 @@ CFLAGS+=-Wall -I${.CURDIR}/../../sbin/pfctl -I${.CURDIR}/../hostapd # for pcap-int.h CFLAGS+=-I${.CURDIR}/../../lib/libpcap -CFLAGS+=-DCSLIP -DPPP -DHAVE_FDDI -DETHER_SERVICE -DRETSIGTYPE=void -DHAVE_NET_SLIP_H -DHAVE_ETHER_NTOHOST -DINET6 +CFLAGS+=-DCSLIP -DPPP -DHAVE_FDDI -DETHER_SERVICE -DHAVE_NET_SLIP_H -DHAVE_ETHER_NTOHOST -DINET6 LDADD+= -lpcap -ll -lcrypto DPADD+= ${LIBL} ${LIBPCAP} ${LIBCRYPTO} diff --git a/usr.sbin/tcpdump/setsignal.c b/usr.sbin/tcpdump/setsignal.c index cf761a1e9d6..bda4f889994 100644 --- a/usr.sbin/tcpdump/setsignal.c +++ b/usr.sbin/tcpdump/setsignal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setsignal.c,v 1.5 2015/04/05 17:02:57 guenther Exp $ */ +/* $OpenBSD: setsignal.c,v 1.6 2015/10/14 04:55:17 guenther Exp $ */ /* * Copyright (c) 1997 @@ -23,52 +23,23 @@ #include -#ifdef HAVE_MEMORY_H -#include -#endif #include -#ifdef HAVE_SIGACTION #include -#endif - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif #include "setsignal.h" -/* - * An os independent signal() with BSD semantics, e.g. the signal - * catcher is restored following service of the signal. - * - * 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. - * - * Did I mention that signals suck? - */ -RETSIGTYPE -(*setsignal (int sig, RETSIGTYPE (*func)(int)))(int) +void +setsignal(int sig, void (*func)(int)) { -#ifdef HAVE_SIGACTION - struct sigaction old, new; - - 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); - -#else -#ifdef HAVE_SIGSET - return (sigset(sig, func)); -#else - return (signal(sig, func)); -#endif -#endif + struct sigaction sa; + + if (sigaction(sig, NULL, &sa) == 0 && sa.sa_handler != SIG_IGN) { + sa.sa_handler = func; + sa.sa_flags = SA_RESTART; + if (sig == SIGCHLD) + sa.sa_flags |= SA_NOCLDSTOP; + sigemptyset(&sa.sa_mask); + sigaction(sig, &sa, NULL); + } } diff --git a/usr.sbin/tcpdump/setsignal.h b/usr.sbin/tcpdump/setsignal.h index a83a8356784..1b33d36192f 100644 --- a/usr.sbin/tcpdump/setsignal.h +++ b/usr.sbin/tcpdump/setsignal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: setsignal.h,v 1.3 2007/10/07 16:41:05 deraadt Exp $ */ +/* $OpenBSD: setsignal.h,v 1.4 2015/10/14 04:55:17 guenther Exp $ */ /* * Copyright (c) 1997 @@ -20,10 +20,10 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Id: setsignal.h,v 1.3 2007/10/07 16:41:05 deraadt Exp $ (LBL) + * @(#) $Id: setsignal.h,v 1.4 2015/10/14 04:55:17 guenther Exp $ (LBL) */ #ifndef setsignal_h #define setsignal_h -RETSIGTYPE (*setsignal(int, RETSIGTYPE (*)(int)))(int); +void setsignal(int, void (*)(int)); #endif diff --git a/usr.sbin/tcpdump/tcpdump.c b/usr.sbin/tcpdump/tcpdump.c index 98d729b1cd1..a0ed77cc7d6 100644 --- a/usr.sbin/tcpdump/tcpdump.c +++ b/usr.sbin/tcpdump/tcpdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcpdump.c,v 1.74 2015/10/09 01:37:09 deraadt Exp $ */ +/* $OpenBSD: tcpdump.c,v 1.75 2015/10/14 04:55:17 guenther Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -92,8 +92,8 @@ extern void bpf_dump(struct bpf_program *, int); extern int esp_init(char *); /* Forwards */ -RETSIGTYPE cleanup(int); -RETSIGTYPE gotchld(int); +void cleanup(int); +void gotchld(int); extern __dead void usage(void); /* Length of saved portion of packet. */ @@ -503,8 +503,7 @@ main(int argc, char **argv) } /* make a clean exit on interrupts */ -/* ARGSUSED */ -RETSIGTYPE +void cleanup(int signo) { struct pcap_stat stat; @@ -533,8 +532,7 @@ cleanup(int signo) _exit(0); } -/* ARGSUSED */ -RETSIGTYPE +void gotchld(int signo) { pid_t pid; @@ -681,14 +679,10 @@ default_print(register const u_char *bp, register u_int length) void set_slave_signals(void) { - RETSIGTYPE (*oldhandler)(int); - setsignal(SIGTERM, cleanup); setsignal(SIGINT, cleanup); setsignal(SIGCHLD, gotchld); - /* Cooperate with nohup(1) XXX is this still necessary/working? */ - if ((oldhandler = setsignal(SIGHUP, cleanup)) != SIG_DFL) - (void)setsignal(SIGHUP, oldhandler); + setsignal(SIGHUP, cleanup); } __dead void -- 2.20.1