summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-01-31 15:13:04 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-01-31 15:13:04 +0000
commitc2891839b0f8b07a233c81baaaa3eabd6aee35e8 (patch)
treef395df6bc43dc40036d79b2c5cc464172bb48539 /usr.sbin/tcpdump
parent1c305a43428dddc9cc073448f538e307bcd2e7e7 (diff)
general cleanup and better SIGCHLD handling from millert@
ok canacar@
Diffstat (limited to 'usr.sbin/tcpdump')
-rw-r--r--usr.sbin/tcpdump/Makefile5
-rw-r--r--usr.sbin/tcpdump/addrtoname.c10
-rw-r--r--usr.sbin/tcpdump/privsep.c22
-rw-r--r--usr.sbin/tcpdump/privsep.h7
4 files changed, 21 insertions, 23 deletions
diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile
index bb92ffb8675..31340fc215c 100644
--- a/usr.sbin/tcpdump/Makefile
+++ b/usr.sbin/tcpdump/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.43 2004/01/28 19:44:55 canacar Exp $
+# $OpenBSD: Makefile,v 1.44 2004/01/31 15:13:03 otto Exp $
#
# Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
# The Regents of the University of California. All rights reserved.
@@ -34,9 +34,6 @@ CFLAGS+=-DLBL_ALIGN
LDADD+= -lpcap -ll -lcrypto
DPADD+= ${LIBL} ${LIBPCAP} ${LIBCRYPTO}
-#BINMODE=4555
-#BINOWN= root
-
SRCS= tcpdump.c addrtoname.c privsep.c privsep_fdpass.c privsep_pcap.c \
print-ether.c print-ip.c print-arp.c print-tcp.c print-udp.c \
print-atalk.c print-domain.c print-tftp.c print-bootp.c print-nfs.c \
diff --git a/usr.sbin/tcpdump/addrtoname.c b/usr.sbin/tcpdump/addrtoname.c
index 2c2d6d9faeb..9aa41982f97 100644
--- a/usr.sbin/tcpdump/addrtoname.c
+++ b/usr.sbin/tcpdump/addrtoname.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: addrtoname.c,v 1.20 2004/01/28 19:44:55 canacar Exp $ */
+/* $OpenBSD: addrtoname.c,v 1.21 2004/01/31 15:13:03 otto Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -25,7 +25,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.c,v 1.20 2004/01/28 19:44:55 canacar Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.c,v 1.21 2004/01/31 15:13:03 otto Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -224,8 +224,8 @@ getname(const u_char *ap)
(addr & f_netmask) == f_localnet &&
(aflag ||
!((addr & ~netmask) == 0 || (addr | netmask) == 0xffffffff))) {
- int n = priv_gethostbyaddr((char *)&addr, 4, AF_INET,
- host, sizeof(host));
+ size_t n = priv_gethostbyaddr((char *)&addr, sizeof(addr),
+ AF_INET, host, sizeof(host));
if (n > 0) {
char *dotp;
@@ -283,7 +283,7 @@ getname6(const u_char *ap)
!((addr & ~netmask) == 0 || (addr | netmask) == 0xffffffff))
#endif
) {
- int n = priv_gethostbyaddr((char *)&addr, sizeof(addr),
+ size_t n = priv_gethostbyaddr((char *)&addr, sizeof(addr),
AF_INET6, host, sizeof(host));
if (n > 0) {
char *dotp;
diff --git a/usr.sbin/tcpdump/privsep.c b/usr.sbin/tcpdump/privsep.c
index 91d07f7cd14..b7fa5d85584 100644
--- a/usr.sbin/tcpdump/privsep.c
+++ b/usr.sbin/tcpdump/privsep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.c,v 1.1 2004/01/28 19:44:55 canacar Exp $ */
+/* $OpenBSD: privsep.c,v 1.2 2004/01/31 15:13:03 otto Exp $ */
/*
* Copyright (c) 2003 Can Erkin Acar
@@ -108,6 +108,8 @@ priv_init(int argc, char **argv)
char *WFileName = NULL;
closefrom(STDERR_FILENO + 1);
+ for (i = 1; i < _NSIG; i++)
+ signal(i, SIG_DFL);
/* Create sockets */
if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, socks) == -1)
@@ -199,9 +201,6 @@ priv_init(int argc, char **argv)
else
cmdbuf = copy_argv(&argv[optind]);
- for (i = 1; i < _NSIG; i++)
- signal(i, SIG_DFL);
-
/* Pass ALRM/TERM/HUP through to child, and accept CHLD */
signal(SIGALRM, sig_pass_to_chld);
signal(SIGTERM, sig_pass_to_chld);
@@ -706,9 +705,8 @@ priv_getline(char *line, size_t line_len)
static void
sig_pass_to_chld(int sig)
{
- int save_err;
+ int save_err = errno;
- save_err = errno;
if (child_pid != -1)
kill(child_pid, sig);
errno = save_err;
@@ -718,14 +716,18 @@ sig_pass_to_chld(int sig)
static void
sig_got_chld(int sig)
{
- int save_err;
pid_t pid;
int status;
+ int save_err = errno;
+
+ do {
+ pid = waitpid(child_pid, &status, WNOHANG);
+ } while (pid == -1 && errno == EINTR);
- save_err = errno;
- pid = waitpid(child_pid, &status, WCONTINUED);
- if ((pid == -1 || !WIFCONTINUED(status)) && cur_state < STATE_QUIT)
+ if (pid == child_pid && (WIFEXITED(status) || WIFSIGNALED(status)) &&
+ cur_state < STATE_QUIT)
cur_state = STATE_QUIT;
+
errno = save_err;
}
diff --git a/usr.sbin/tcpdump/privsep.h b/usr.sbin/tcpdump/privsep.h
index 07b4fb5b1f5..756c1500127 100644
--- a/usr.sbin/tcpdump/privsep.h
+++ b/usr.sbin/tcpdump/privsep.h
@@ -64,15 +64,14 @@ void priv_getserventries(void);
/* Retrieve a single service entry, should be called repeatedly after
calling priv_getserventries() until it returns zero */
-size_t priv_getserventry(char *name, size_t name_len, int *port, char *prot,
- size_t prot_len);
+size_t priv_getserventry(char *, size_t, int *, char *, size_t);
/* Start getting ip protocol entries */
void priv_getprotoentries(void);
/* Retrieve a single protocol entry, should be called repeatedly after
calling priv_getprotoentries() until it returns zero */
-size_t priv_getprotoentry(char *name, size_t name_len, int *num);
+size_t priv_getprotoentry(char *, size_t, int *);
/* Start getting lines from a file */
void priv_getlines(size_t);
@@ -94,7 +93,7 @@ void must_write(int, const void *, size_t);
size_t read_block(int, char *, size_t, const char *);
size_t read_string(int, char *, size_t, const char *);
void write_block(int, size_t, const char *);
-void write_command(int fd, int cmd);
+void write_command(int, int);
void write_string(int, const char *);
void write_zero(int);