diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-10-24 03:33:35 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-10-24 03:33:35 +0000 |
commit | abe034b2684c4dae218b716d54205cd11f76afb1 (patch) | |
tree | f1bc221324ee6f67cbed1fa7a01d598bf4d3e962 /tshark.c | |
parent | b1b6104e260d943f478419b358cb1f8e0ec5745c (diff) |
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.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@23256 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'tshark.c')
-rw-r--r-- | tshark.c | 50 |
1 files changed, 21 insertions, 29 deletions
@@ -1710,7 +1710,7 @@ capture(void) fd_set readfds; #endif #ifndef _WIN32 - void (*oldhandler)(int); + struct sigaction action, oldaction; #endif /* @@ -1745,18 +1745,23 @@ capture(void) SetConsoleCtrlHandler(capture_cleanup, TRUE); #else /* _WIN32 */ /* Catch SIGINT and SIGTERM and, if we get either of them, clean up - and exit. - XXX - deal with signal semantics on various UNIX platforms. Or just - use "sigaction()" and be done with it? */ - signal(SIGTERM, capture_cleanup); - signal(SIGINT, capture_cleanup); - if ((oldhandler = signal(SIGHUP, capture_cleanup)) != SIG_DFL) - signal(SIGHUP, oldhandler); + and exit. */ + action.sa_handler = capture_cleanup; + action.sa_flags = 0; + action.sa_mask = 0; + sigaction(SIGTERM, &action, NULL); + sigaction(SIGINT, &action, NULL); + sigaction(SIGHUP, NULL, &oldaction); + if (oldaction.sa_handler == SIG_DFL) + sigaction(SIGHUP, &action, NULL); #ifdef SIGINFO /* 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. */ - 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 /* _WIN32 */ @@ -2015,13 +2020,6 @@ capture_input_new_packets(capture_options *capture_opts, int to_read) static 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) { /* Report the count only if we aren't printing a packet count as packets arrive. */ @@ -2071,22 +2069,16 @@ capture_input_drops(capture_options *capture_opts _U_, int dropped) void capture_input_closed(capture_options *capture_opts) { - if (!print_packet_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");*/ + report_counts(); - if(capture_opts->cf != NULL && ((capture_file *) capture_opts->cf)->wth != NULL) { - wtap_close(((capture_file *) capture_opts->cf)->wth); - } + if(capture_opts->cf != NULL && ((capture_file *) capture_opts->cf)->wth != NULL) { + wtap_close(((capture_file *) capture_opts->cf)->wth); + } #ifdef USE_BROKEN_G_MAIN_LOOP - /*g_main_loop_quit(loop);*/ - g_main_quit(loop); + /*g_main_loop_quit(loop);*/ + g_main_quit(loop); #else - loop_running = FALSE; + loop_running = FALSE; #endif } |