summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-02 16:19:28 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-02 16:19:28 +0000
commit9a220fbad5dd513de55c52e6eb1152e0f0783100 (patch)
tree50bc69cfa27cc27918b5d90e9eea076c5eecbda1 /usr.sbin/tcpdump
parent9febefcdc8bbe67c76e7b5f06c021a521d72f51e (diff)
avoid stdio in signal handler (not complete yet)
Diffstat (limited to 'usr.sbin/tcpdump')
-rw-r--r--usr.sbin/tcpdump/tcpdump.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/usr.sbin/tcpdump/tcpdump.c b/usr.sbin/tcpdump/tcpdump.c
index 6caecbc9df6..7cc35b12872 100644
--- a/usr.sbin/tcpdump/tcpdump.c
+++ b/usr.sbin/tcpdump/tcpdump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcpdump.c,v 1.22 2001/06/25 23:05:17 provos Exp $ */
+/* $OpenBSD: tcpdump.c,v 1.23 2001/11/02 16:19:27 deraadt Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -26,7 +26,7 @@ static const char copyright[] =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.22 2001/06/25 23:05:17 provos Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.23 2001/11/02 16:19:27 deraadt Exp $ (LBL)";
#endif
/*
@@ -385,23 +385,26 @@ RETSIGTYPE
cleanup(int signo)
{
struct pcap_stat stat;
+ char buf[1024];
/* Can't print the summary if reading from a savefile */
if (pd != NULL && pcap_file(pd) == NULL) {
- /* XXX unsafe */
- (void)fflush(stdout);
- putc('\n', stderr);
- if (pcap_stats(pd, &stat) < 0)
- (void)fprintf(stderr, "pcap_stats: %s\n",
- pcap_geterr(pd));
- else {
- (void)fprintf(stderr, "%d packets received by filter\n",
- stat.ps_recv);
- (void)fprintf(stderr, "%d packets dropped by kernel\n",
- stat.ps_drop);
+ (void)fflush(stdout); /* XXX unsafe */
+ (void)write(STDERR_FILENO, "\n", 1);
+ if (pcap_stats(pd, &stat) < 0) {
+ (void)snprintf(buf, sizeof buf,
+ "pcap_stats: %s\n", pcap_geterr(pd));
+ write(STDOUT_FILENO, buf, strlen(buf));
+ } else {
+ (void)snprintf(buf, sizeof buf,
+ "%d packets received by filter\n", stat.ps_recv);
+ write(STDOUT_FILENO, buf, strlen(buf));
+ (void)snprintf(buf, sizeof buf,
+ "%d packets dropped by kernel\n", stat.ps_drop);
+ write(STDOUT_FILENO, buf, strlen(buf));
}
}
- exit(0);
+ _exit(0);
}
/* dump the buffer in `emacs-hexl' style */