Use sigaction(), not signal(), so we know what its semantics are (and so

that we can find out what the signal action for SIGHUP is without
changing it).

That renders report_counts() safe to use at the end of a capture; do so.

Clean up indentation.

svn path=/trunk/; revision=23256
This commit is contained in:
Guy Harris 2007-10-24 03:33:35 +00:00
parent 1b69944c45
commit 2ef0350a47
1 changed files with 21 additions and 29 deletions

View File

@ -1710,7 +1710,7 @@ capture(void)
fd_set readfds; fd_set readfds;
#endif #endif
#ifndef _WIN32 #ifndef _WIN32
void (*oldhandler)(int); struct sigaction action, oldaction;
#endif #endif
/* /*
@ -1745,18 +1745,23 @@ capture(void)
SetConsoleCtrlHandler(capture_cleanup, TRUE); SetConsoleCtrlHandler(capture_cleanup, TRUE);
#else /* _WIN32 */ #else /* _WIN32 */
/* Catch SIGINT and SIGTERM and, if we get either of them, clean up /* Catch SIGINT and SIGTERM and, if we get either of them, clean up
and exit. and exit. */
XXX - deal with signal semantics on various UNIX platforms. Or just action.sa_handler = capture_cleanup;
use "sigaction()" and be done with it? */ action.sa_flags = 0;
signal(SIGTERM, capture_cleanup); action.sa_mask = 0;
signal(SIGINT, capture_cleanup); sigaction(SIGTERM, &action, NULL);
if ((oldhandler = signal(SIGHUP, capture_cleanup)) != SIG_DFL) sigaction(SIGINT, &action, NULL);
signal(SIGHUP, oldhandler); sigaction(SIGHUP, NULL, &oldaction);
if (oldaction.sa_handler == SIG_DFL)
sigaction(SIGHUP, &action, NULL);
#ifdef SIGINFO #ifdef SIGINFO
/* Catch SIGINFO and, if we get it and we're capturing to a file in /* Catch SIGINFO and, if we get it and we're capturing to a file in
quiet mode, report the number of packets we've captured. */ quiet mode, report the number of packets we've captured. */
signal(SIGINFO, report_counts_siginfo); action.sa_handler = report_counts_siginfo;
action.sa_flags = 0;
action.sa_mask = 0;
sigaction(SIGINFO, &action, NULL);
#endif /* SIGINFO */ #endif /* SIGINFO */
#endif /* _WIN32 */ #endif /* _WIN32 */
@ -2015,13 +2020,6 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
static void static void
report_counts(void) report_counts(void)
{ {
#ifdef SIGINFO
/* XXX - if we use sigaction, this doesn't have to be done.
(Yes, this isn't necessary on BSD, but just in case a system
where "signal()" has AT&T semantics adopts SIGINFO....) */
signal(SIGINFO, report_counts_siginfo);
#endif /* SIGINFO */
if (!print_packet_counts) { if (!print_packet_counts) {
/* Report the count only if we aren't printing a packet count /* Report the count only if we aren't printing a packet count
as packets arrive. */ as packets arrive. */
@ -2071,13 +2069,7 @@ capture_input_drops(capture_options *capture_opts _U_, int dropped)
void void
capture_input_closed(capture_options *capture_opts) capture_input_closed(capture_options *capture_opts)
{ {
if (!print_packet_counts) { report_counts();
/* Report the count only if we aren't printing a packet count
as packets arrive. */
fprintf(stderr, "%u packets captured\n", packet_count);
}
/*printf("capture_input_closed\n");*/
if(capture_opts->cf != NULL && ((capture_file *) capture_opts->cf)->wth != NULL) { if(capture_opts->cf != NULL && ((capture_file *) capture_opts->cf)->wth != NULL) {
wtap_close(((capture_file *) capture_opts->cf)->wth); wtap_close(((capture_file *) capture_opts->cf)->wth);