summaryrefslogtreecommitdiff
path: root/capture_sync.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2007-11-25 21:33:34 +0000
committerGerald Combs <gerald@wireshark.org>2007-11-25 21:33:34 +0000
commit060834df82011c9332a414bbd5f470928090c0d7 (patch)
tree88a52e35a59c1c9609b3daab765ed786a054e00d /capture_sync.c
parent4e9892cbfd15a4473c553ed31a8072f9e006158d (diff)
downloadwireshark-060834df82011c9332a414bbd5f470928090c0d7.tar.gz
If a child doesn't quit 500ms after sending a QUIT signal, force it to exit.
svn path=/trunk/; revision=23591
Diffstat (limited to 'capture_sync.c')
-rw-r--r--capture_sync.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/capture_sync.c b/capture_sync.c
index fc3c88e1e7..da444f5b59 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -1341,14 +1341,40 @@ signal_pipe_capquit_to_child(capture_options *capture_opts)
void
sync_pipe_stop(capture_options *capture_opts)
{
+#ifdef _WIN32
+ int count;
+ DWORD childstatus;
+ gboolean terminate = TRUE;
+#endif
+
if (capture_opts->fork_child != -1) {
#ifndef _WIN32
/* send the SIGUSR1 signal to close the capture child gracefully. */
kill(capture_opts->fork_child, SIGUSR1);
#else
- /* Win32 doesn't have the kill() system call, use the special signal pipe
- instead to close the capture child gracefully. */
+#define STOP_SLEEP_TIME 500 /* ms */
+#define STOP_CHECK_TIME 50
+ /* First, use the special signal pipe to try to close the capture child
+ * gracefully.
+ */
signal_pipe_capquit_to_child(capture_opts);
+
+ /* Next, wait for the process to exit on its own */
+ for (count = 0; count < STOP_SLEEP_TIME / STOP_CHECK_TIME; count++) {
+ if (GetExitCodeProcess((HANDLE) capture_opts->fork_child, &childstatus) &&
+ childstatus != STILL_ACTIVE) {
+ terminate = FALSE;
+ break;
+ }
+ Sleep(STOP_CHECK_TIME);
+ }
+
+ /* Force the issue. */
+ if (terminate) {
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
+ "sync_pipe_stop: forcing child to exit");
+ sync_pipe_kill(capture_opts->fork_child);
+ }
#endif
}
}