Update:
[obnox/wireshark/wip.git] / capture_sync.c
index 191cd198fd7cb1afdc27ee2472d0b89b7cbb1771..02223ef28a80d978cffb1d0b3f9e540d3a7529e5 100644 (file)
  * macros) on UNIX systems that don't have them.
  */
 #ifndef WIFEXITED
-# define WIFEXITED(status)     (((status) & 0177) == 0)
+# define WIFEXITED(status)      (((status) & 0177) == 0)
 #endif
 #ifndef WIFSTOPPED
-# define WIFSTOPPED(status)    (((status) & 0177) == 0177)
+# define WIFSTOPPED(status)     (((status) & 0177) == 0177)
 #endif
 #ifndef WIFSIGNALED
-# define WIFSIGNALED(status)   (!WIFSTOPPED(status) && !WIFEXITED(status))
+# define WIFSIGNALED(status)    (!WIFSTOPPED(status) && !WIFEXITED(status))
 #endif
 #ifndef WEXITSTATUS
-# define WEXITSTATUS(status)   ((status) >> 8)
+# define WEXITSTATUS(status)    ((status) >> 8)
 #endif
 #ifndef WTERMSIG
-# define WTERMSIG(status)      ((status) & 0177)
+# define WTERMSIG(status)       ((status) & 0177)
 #endif
 #ifndef WCOREDUMP
-# define WCOREDUMP(status)     ((status) & 0200)
+# define WCOREDUMP(status)      ((status) & 0200)
 #endif
 #ifndef WSTOPSIG
-# define WSTOPSIG(status)      ((status) >> 8)
+# define WSTOPSIG(status)       ((status) >> 8)
 #endif
 #endif /* _WIN32 */
 
@@ -97,7 +97,9 @@
 #ifdef _WIN32
 #include "capture-wpcap.h"
 #endif
-#include "ui_util.h"
+
+#include "ui/ui_util.h"
+
 #include <wsutil/file_util.h>
 #include "log.h"
 
@@ -125,24 +127,23 @@ static int pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
 static const char **
 sync_pipe_add_arg(const char **args, int *argc, const char *arg)
 {
-  /* Grow the array; "*argc" currently contains the number of string
-     pointers, *not* counting the NULL pointer at the end, so we have
-     to add 2 in order to get the new size of the array, including the
-     new pointer and the terminating NULL pointer. */
-  args = g_realloc( (gpointer) args, (*argc + 2) * sizeof (char *));
-
-  /* Stuff the pointer into the penultimate element of the array, which
-     is the one at the index specified by "*argc". */
-  args[*argc] = arg;
-
-  /* Now bump the count. */
-  (*argc)++;
-
-  /* We overwrite the NULL pointer; put it back right after the
-     element we added. */
-  args[*argc] = NULL;
-
-  return args;
+    /* Grow the array; "*argc" currently contains the number of string
+       pointers, *not* counting the NULL pointer at the end, so we have
+       to add 2 in order to get the new size of the array, including the
+       new pointer and the terminating NULL pointer. */
+    args = g_realloc( (gpointer) args, (*argc + 2) * sizeof (char *));
+
+    /* Stuff the pointer into the penultimate element of the array, which
+       is the one at the index specified by "*argc". */
+    args[*argc] = g_strdup(arg);
+    /* Now bump the count. */
+    (*argc)++;
+
+    /* We overwrite the NULL pointer; put it back right after the
+       element we added. */
+    args[*argc] = NULL;
+
+    return args;
 }
 
 
@@ -249,39 +250,39 @@ win32strexception(DWORD exception)
 {
     static char errbuf[ERRBUF_SIZE+1];
     static const struct exception_msg {
-      int code;
-      char *msg;
+        int code;
+        char *msg;
     } exceptions[] = {
-      { EXCEPTION_ACCESS_VIOLATION, "Access violation" },
-      { EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "Array bounds exceeded" },
-      { EXCEPTION_BREAKPOINT, "Breakpoint" },
-      { EXCEPTION_DATATYPE_MISALIGNMENT, "Data type misalignment" },
-      { EXCEPTION_FLT_DENORMAL_OPERAND, "Denormal floating-point operand" },
-      { EXCEPTION_FLT_DIVIDE_BY_ZERO, "Floating-point divide by zero" },
-      { EXCEPTION_FLT_INEXACT_RESULT, "Floating-point inexact result" },
-      { EXCEPTION_FLT_INVALID_OPERATION, "Invalid floating-point operation" },
-      { EXCEPTION_FLT_OVERFLOW, "Floating-point overflow" },
-      { EXCEPTION_FLT_STACK_CHECK, "Floating-point stack check" },
-      { EXCEPTION_FLT_UNDERFLOW, "Floating-point underflow" },
-      { EXCEPTION_GUARD_PAGE, "Guard page violation" },
-      { EXCEPTION_ILLEGAL_INSTRUCTION, "Illegal instruction" },
-      { EXCEPTION_IN_PAGE_ERROR, "Page-in error" },
-      { EXCEPTION_INT_DIVIDE_BY_ZERO, "Integer divide by zero" },
-      { EXCEPTION_INT_OVERFLOW, "Integer overflow" },
-      { EXCEPTION_INVALID_DISPOSITION, "Invalid disposition" },
-      { EXCEPTION_INVALID_HANDLE, "Invalid handle" },
-      { EXCEPTION_NONCONTINUABLE_EXCEPTION, "Non-continuable exception" },
-      { EXCEPTION_PRIV_INSTRUCTION, "Privileged instruction" },
-      { EXCEPTION_SINGLE_STEP, "Single-step complete" },
-      { EXCEPTION_STACK_OVERFLOW, "Stack overflow" },
-      { 0, NULL }
+        { EXCEPTION_ACCESS_VIOLATION, "Access violation" },
+        { EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "Array bounds exceeded" },
+        { EXCEPTION_BREAKPOINT, "Breakpoint" },
+        { EXCEPTION_DATATYPE_MISALIGNMENT, "Data type misalignment" },
+        { EXCEPTION_FLT_DENORMAL_OPERAND, "Denormal floating-point operand" },
+        { EXCEPTION_FLT_DIVIDE_BY_ZERO, "Floating-point divide by zero" },
+        { EXCEPTION_FLT_INEXACT_RESULT, "Floating-point inexact result" },
+        { EXCEPTION_FLT_INVALID_OPERATION, "Invalid floating-point operation" },
+        { EXCEPTION_FLT_OVERFLOW, "Floating-point overflow" },
+        { EXCEPTION_FLT_STACK_CHECK, "Floating-point stack check" },
+        { EXCEPTION_FLT_UNDERFLOW, "Floating-point underflow" },
+        { EXCEPTION_GUARD_PAGE, "Guard page violation" },
+        { EXCEPTION_ILLEGAL_INSTRUCTION, "Illegal instruction" },
+        { EXCEPTION_IN_PAGE_ERROR, "Page-in error" },
+        { EXCEPTION_INT_DIVIDE_BY_ZERO, "Integer divide by zero" },
+        { EXCEPTION_INT_OVERFLOW, "Integer overflow" },
+        { EXCEPTION_INVALID_DISPOSITION, "Invalid disposition" },
+        { EXCEPTION_INVALID_HANDLE, "Invalid handle" },
+        { EXCEPTION_NONCONTINUABLE_EXCEPTION, "Non-continuable exception" },
+        { EXCEPTION_PRIV_INSTRUCTION, "Privileged instruction" },
+        { EXCEPTION_SINGLE_STEP, "Single-step complete" },
+        { EXCEPTION_STACK_OVERFLOW, "Stack overflow" },
+        { 0, NULL }
     };
-#define N_EXCEPTIONS   (sizeof exceptions / sizeof exceptions[0])
+#define N_EXCEPTIONS    (sizeof exceptions / sizeof exceptions[0])
     int i;
 
     for (i = 0; i < N_EXCEPTIONS; i++) {
-       if (exceptions[i].code == exception)
-         return exceptions[i].msg;
+        if (exceptions[i].code == exception)
+            return exceptions[i].msg;
     }
     g_snprintf(errbuf, (gulong)sizeof errbuf, "Exception 0x%08x", exception);
     return errbuf;
@@ -377,101 +378,55 @@ sync_pipe_start(capture_options *capture_opts) {
     }
 
     if (capture_opts->ifaces->len > 1)
-      argv = sync_pipe_add_arg(argv, &argc, "-t");
+        argv = sync_pipe_add_arg(argv, &argc, "-t");
 
     if (capture_opts->use_pcapng)
-      argv = sync_pipe_add_arg(argv, &argc, "-n");
+        argv = sync_pipe_add_arg(argv, &argc, "-n");
+    else
+        argv = sync_pipe_add_arg(argv, &argc, "-P");
 
     if (capture_opts->multi_files_on) {
-      if (capture_opts->has_autostop_filesize) {
-        argv = sync_pipe_add_arg(argv, &argc, "-b");
-        g_snprintf(sfilesize, ARGV_NUMBER_LEN, "filesize:%d",capture_opts->autostop_filesize);
-        argv = sync_pipe_add_arg(argv, &argc, sfilesize);
-      }
-
-      if (capture_opts->has_file_duration) {
-        argv = sync_pipe_add_arg(argv, &argc, "-b");
-        g_snprintf(sfile_duration, ARGV_NUMBER_LEN, "duration:%d",capture_opts->file_duration);
-        argv = sync_pipe_add_arg(argv, &argc, sfile_duration);
-      }
-
-      if (capture_opts->has_ring_num_files) {
-        argv = sync_pipe_add_arg(argv, &argc, "-b");
-        g_snprintf(sring_num_files, ARGV_NUMBER_LEN, "files:%d",capture_opts->ring_num_files);
-        argv = sync_pipe_add_arg(argv, &argc, sring_num_files);
-      }
-
-      if (capture_opts->has_autostop_files) {
-        argv = sync_pipe_add_arg(argv, &argc, "-a");
-        g_snprintf(sautostop_files, ARGV_NUMBER_LEN, "files:%d",capture_opts->autostop_files);
-        argv = sync_pipe_add_arg(argv, &argc, sautostop_files);
-      }
+        if (capture_opts->has_autostop_filesize) {
+            argv = sync_pipe_add_arg(argv, &argc, "-b");
+            g_snprintf(sfilesize, ARGV_NUMBER_LEN, "filesize:%d",capture_opts->autostop_filesize);
+            argv = sync_pipe_add_arg(argv, &argc, sfilesize);
+        }
+
+        if (capture_opts->has_file_duration) {
+            argv = sync_pipe_add_arg(argv, &argc, "-b");
+            g_snprintf(sfile_duration, ARGV_NUMBER_LEN, "duration:%d",capture_opts->file_duration);
+            argv = sync_pipe_add_arg(argv, &argc, sfile_duration);
+        }
+
+        if (capture_opts->has_ring_num_files) {
+            argv = sync_pipe_add_arg(argv, &argc, "-b");
+            g_snprintf(sring_num_files, ARGV_NUMBER_LEN, "files:%d",capture_opts->ring_num_files);
+            argv = sync_pipe_add_arg(argv, &argc, sring_num_files);
+        }
+
+        if (capture_opts->has_autostop_files) {
+            argv = sync_pipe_add_arg(argv, &argc, "-a");
+            g_snprintf(sautostop_files, ARGV_NUMBER_LEN, "files:%d",capture_opts->autostop_files);
+            argv = sync_pipe_add_arg(argv, &argc, sautostop_files);
+        }
     } else {
         if (capture_opts->has_autostop_filesize) {
-          argv = sync_pipe_add_arg(argv, &argc, "-a");
-          g_snprintf(sautostop_filesize, ARGV_NUMBER_LEN, "filesize:%d",capture_opts->autostop_filesize);
-          argv = sync_pipe_add_arg(argv, &argc, sautostop_filesize);
+            argv = sync_pipe_add_arg(argv, &argc, "-a");
+            g_snprintf(sautostop_filesize, ARGV_NUMBER_LEN, "filesize:%d",capture_opts->autostop_filesize);
+            argv = sync_pipe_add_arg(argv, &argc, sautostop_filesize);
         }
     }
 
     if (capture_opts->has_autostop_packets) {
-      argv = sync_pipe_add_arg(argv, &argc, "-c");
-      g_snprintf(scount, ARGV_NUMBER_LEN, "%d",capture_opts->autostop_packets);
-      argv = sync_pipe_add_arg(argv, &argc, scount);
+        argv = sync_pipe_add_arg(argv, &argc, "-c");
+        g_snprintf(scount, ARGV_NUMBER_LEN, "%d",capture_opts->autostop_packets);
+        argv = sync_pipe_add_arg(argv, &argc, scount);
     }
 
     if (capture_opts->has_autostop_duration) {
-      argv = sync_pipe_add_arg(argv, &argc, "-a");
-      g_snprintf(sautostop_duration, ARGV_NUMBER_LEN, "duration:%d",capture_opts->autostop_duration);
-      argv = sync_pipe_add_arg(argv, &argc, sautostop_duration);
-    }
-    if (capture_opts->ifaces->len == 0) {
-        interface_opts.name = g_strdup(capture_opts->iface);
-        if (capture_opts->iface_descr) {
-            interface_opts.descr = g_strdup(capture_opts->iface_descr);
-        } else {
-            interface_opts.descr = NULL;
-        }
-        interface_opts.cfilter = g_strdup(capture_opts->cfilter);
-        interface_opts.snaplen = capture_opts->snaplen;
-        interface_opts.linktype = capture_opts->linktype;
-        interface_opts.promisc_mode = capture_opts->promisc_mode;
-#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
-        interface_opts.buffer_size = capture_opts->buffer_size;
-#endif
-        interface_opts.monitor_mode = capture_opts->monitor_mode;
-#ifdef HAVE_PCAP_REMOTE
-        interface_opts.src_type = capture_opts->src_type;
-        if (capture_opts->remote_host) {
-            interface_opts.remote_host = g_strdup(capture_opts->remote_host);
-        } else {
-            interface_opts.remote_host = NULL;
-        }
-        if (capture_opts->remote_port) {
-            interface_opts.remote_port = g_strdup(capture_opts->remote_port);
-        } else {
-            interface_opts.remote_port = NULL;
-        }
-        interface_opts.auth_type = capture_opts->auth_type;
-        if (capture_opts->auth_username) {
-            interface_opts.auth_username = g_strdup(capture_opts->auth_username);
-        } else {
-            interface_opts.auth_username = NULL;
-        }
-        if (capture_opts->auth_password) {
-            interface_opts.auth_password = g_strdup(capture_opts->auth_password);
-        } else {
-            interface_opts.auth_password = NULL;
-        }
-        interface_opts.datatx_udp = capture_opts->datatx_udp;
-        interface_opts.nocap_rpcap = capture_opts->nocap_rpcap;
-        interface_opts.nocap_local = capture_opts->nocap_local;
-#endif
-#ifdef HAVE_PCAP_SETSAMPLING
-        interface_opts.sampling_method = capture_opts->sampling_method;
-        interface_opts.sampling_param  = capture_opts->sampling_param;
-#endif
-        g_array_append_val(capture_opts->ifaces, interface_opts);
+        argv = sync_pipe_add_arg(argv, &argc, "-a");
+        g_snprintf(sautostop_duration, ARGV_NUMBER_LEN, "duration:%d",capture_opts->autostop_duration);
+        argv = sync_pipe_add_arg(argv, &argc, sautostop_duration);
     }
 
     for (j = 0; j < capture_opts->ifaces->len; j++) {
@@ -484,7 +439,6 @@ sync_pipe_start(capture_options *capture_opts) {
             argv = sync_pipe_add_arg(argv, &argc, "-f");
             argv = sync_pipe_add_arg(argv, &argc, interface_opts.cfilter);
         }
-
         if (interface_opts.snaplen != WTAP_MAX_PACKET_SIZE) {
             argv = sync_pipe_add_arg(argv, &argc, "-s");
             g_snprintf(ssnap, ARGV_NUMBER_LEN, "%d", interface_opts.snaplen);
@@ -554,11 +508,11 @@ sync_pipe_start(capture_options *capture_opts) {
 #endif
 
     if (capture_opts->save_file) {
-      argv = sync_pipe_add_arg(argv, &argc, "-w");
-      argv = sync_pipe_add_arg(argv, &argc, capture_opts->save_file);
+        argv = sync_pipe_add_arg(argv, &argc, "-w");
+        argv = sync_pipe_add_arg(argv, &argc, capture_opts->save_file);
     }
     for (i = 0; i < argc; i++) {
-      g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "argv[%d]: %s", i, argv[i]);
+        g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "argv[%d]: %s", i, argv[i]);
     }
 
 #ifdef _WIN32
@@ -570,27 +524,31 @@ sync_pipe_start(capture_options *capture_opts) {
     /* Create a pipe for the child process */
     /* (increase this value if you have trouble while fast capture file switches) */
     if (! CreatePipe(&sync_pipe_read, &sync_pipe_write, &sa, 5120)) {
-      /* Couldn't create the pipe between parent and child. */
-      report_failure("Couldn't create sync pipe: %s",
-                     win32strerror(GetLastError()));
-      g_free( (gpointer) argv[0]);
-      g_free( (gpointer) argv);
-      return FALSE;
+        /* Couldn't create the pipe between parent and child. */
+        report_failure("Couldn't create sync pipe: %s",
+                       win32strerror(GetLastError()));
+        for (i = 0; i < argc; i++) {
+            g_free( (gpointer) argv[i]);
+        }
+        g_free( (gpointer) argv);
+        return FALSE;
     }
 
     /* Create the signal pipe */
     signal_pipe_name = g_strdup_printf(SIGNAL_PIPE_FORMAT, control_id);
     signal_pipe = CreateNamedPipe(utf_8to16(signal_pipe_name),
-      PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 65535, 65535, 0, NULL);
+                                  PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 65535, 65535, 0, NULL);
     g_free(signal_pipe_name);
 
     if (signal_pipe == INVALID_HANDLE_VALUE) {
-      /* Couldn't create the signal pipe between parent and child. */
-      report_failure("Couldn't create signal pipe: %s",
-                     win32strerror(GetLastError()));
-      g_free( (gpointer) argv[0]);
-      g_free( (gpointer) argv);
-      return FALSE;
+        /* Couldn't create the signal pipe between parent and child. */
+        report_failure("Couldn't create signal pipe: %s",
+                       win32strerror(GetLastError()));
+        for (i = 0; i < argc; i++) {
+            g_free( (gpointer) argv[i]);
+        }
+        g_free( (gpointer) argv);
+        return FALSE;
     }
 
     /* init STARTUPINFO */
@@ -621,13 +579,15 @@ sync_pipe_start(capture_options *capture_opts) {
     /* call dumpcap */
     if(!CreateProcess(NULL, utf_8to16(args->str), NULL, NULL, TRUE,
                       CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
-      report_failure("Couldn't run %s in child process: %s",
-                     args->str, win32strerror(GetLastError()));
-      CloseHandle(sync_pipe_read);
-      CloseHandle(sync_pipe_write);
-      g_free( (gpointer) argv[0]);
-      g_free( (gpointer) argv);
-      return FALSE;
+        report_failure("Couldn't run %s in child process: %s",
+                       args->str, win32strerror(GetLastError()));
+        CloseHandle(sync_pipe_read);
+        CloseHandle(sync_pipe_write);
+        for (i = 0; i < argc; i++) {
+            g_free( (gpointer) argv[i]);
+        }
+        g_free( (gpointer) argv);
+        return FALSE;
     }
     capture_opts->fork_child = (int) pi.hProcess;
     g_string_free(args, TRUE);
@@ -641,39 +601,43 @@ sync_pipe_start(capture_options *capture_opts) {
 
 #else /* _WIN32 */
     if (pipe(sync_pipe) < 0) {
-      /* Couldn't create the pipe between parent and child. */
-      report_failure("Couldn't create sync pipe: %s", strerror(errno));
-      g_free( (gpointer) argv[0]);
-      g_free(argv);
-      return FALSE;
+        /* Couldn't create the pipe between parent and child. */
+        report_failure("Couldn't create sync pipe: %s", g_strerror(errno));
+        for (i = 0; i < argc; i++) {
+            g_free( (gpointer) argv[i]);
+        }
+        g_free(argv);
+        return FALSE;
     }
 
     if ((capture_opts->fork_child = fork()) == 0) {
-      /*
-       * Child process - run dumpcap with the right arguments to make
-       * it just capture with the specified capture parameters
-       */
-      dup2(sync_pipe[PIPE_WRITE], 2);
-      ws_close(sync_pipe[PIPE_READ]);
-      execv(argv[0], (gpointer)argv);
-      g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
-                argv[0], strerror(errno));
-      sync_pipe_errmsg_to_parent(2, errmsg, "");
-
-      /* Exit with "_exit()", so that we don't close the connection
-         to the X server (and cause stuff buffered up by our parent but
-         not yet sent to be sent, as that stuff should only be sent by
-         our parent).  We've sent an error message to the parent, so
-         we exit with an exit status of 1 (any exit status other than
-         0 or 1 will cause an additional message to report that exit
-         status, over and above the error message we sent to the parent). */
-      _exit(1);
+        /*
+         * Child process - run dumpcap with the right arguments to make
+         * it just capture with the specified capture parameters
+         */
+        dup2(sync_pipe[PIPE_WRITE], 2);
+        ws_close(sync_pipe[PIPE_READ]);
+        execv(argv[0], (gpointer)argv);
+        g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
+                   argv[0], g_strerror(errno));
+        sync_pipe_errmsg_to_parent(2, errmsg, "");
+
+        /* Exit with "_exit()", so that we don't close the connection
+           to the X server (and cause stuff buffered up by our parent but
+           not yet sent to be sent, as that stuff should only be sent by
+           our parent).  We've sent an error message to the parent, so
+           we exit with an exit status of 1 (any exit status other than
+           0 or 1 will cause an additional message to report that exit
+           status, over and above the error message we sent to the parent). */
+        _exit(1);
     }
 
     sync_pipe_read_fd = sync_pipe[PIPE_READ];
 #endif
 
-    g_free( (gpointer) argv[0]);  /* exename */
+    for (i = 0; i < argc; i++) {
+        g_free( (gpointer) argv[i]);
+    }
 
     /* Parent process - read messages from the child process over the
        sync pipe. */
@@ -690,13 +654,13 @@ sync_pipe_start(capture_options *capture_opts) {
 #endif
 
     if (capture_opts->fork_child == -1) {
-      /* We couldn't even create the child process. */
-      report_failure("Couldn't create child process: %s", strerror(errno));
-      ws_close(sync_pipe_read_fd);
+        /* We couldn't even create the child process. */
+        report_failure("Couldn't create child process: %s", g_strerror(errno));
+        ws_close(sync_pipe_read_fd);
 #ifdef _WIN32
-      ws_close(capture_opts->signal_pipe_write_fd);
+        ws_close(capture_opts->signal_pipe_write_fd);
 #endif
-      return FALSE;
+        return FALSE;
     }
 
     capture_opts->fork_child_status = 0;
@@ -711,7 +675,7 @@ sync_pipe_start(capture_options *capture_opts) {
 
     /* we have a running capture, now wait for the real capture filename */
     pipe_input_set_handler(sync_pipe_read_fd, (gpointer) capture_opts,
-        &capture_opts->fork_child, sync_pipe_input_cb);
+                           &capture_opts->fork_child, sync_pipe_input_cb);
 
     return TRUE;
 }
@@ -744,13 +708,12 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
     SECURITY_ATTRIBUTES sa;
     STARTUPINFO si;
     PROCESS_INFORMATION pi;
-    int i;
 #else
     char errmsg[1024+1];
     int sync_pipe[2];                       /* pipe used to send messages from child to parent */
     int data_pipe[2];                       /* pipe used to send data from child to parent */
 #endif
-
+    int i;
     *fork_child = -1;
     *data_read_fd = -1;
     *message_read_fd = -1;
@@ -776,7 +739,9 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
         /* Couldn't create the message pipe between parent and child. */
         *msg = g_strdup_printf("Couldn't create sync pipe: %s",
                                win32strerror(GetLastError()));
-        g_free( (gpointer) argv[0]);
+        for (i = 0; argv[i] != NULL; i++) {
+            g_free( (gpointer) argv[i]);
+        }
         g_free( (gpointer) argv);
         return -1;
     }
@@ -789,7 +754,9 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
                                win32strerror(GetLastError()));
         CloseHandle(sync_pipe[PIPE_READ]);
         CloseHandle(sync_pipe[PIPE_WRITE]);
-        g_free( (gpointer) argv[0]);
+        for (i = 0; argv[i] != NULL; i++) {
+            g_free( (gpointer) argv[i]);
+        }
         g_free( (gpointer) argv);
         return -1;
     }
@@ -827,7 +794,9 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
         CloseHandle(data_pipe[PIPE_WRITE]);
         CloseHandle(sync_pipe[PIPE_READ]);
         CloseHandle(sync_pipe[PIPE_WRITE]);
-        g_free( (gpointer) argv[0]);
+        for (i = 0; argv[i] != NULL; i++) {
+            g_free( (gpointer) argv[i]);
+        }
         g_free( (gpointer) argv);
         return -1;
     }
@@ -842,8 +811,10 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
     /* Create a pipe for the child process to send us messages */
     if (pipe(sync_pipe) < 0) {
         /* Couldn't create the message pipe between parent and child. */
-        *msg = g_strdup_printf("Couldn't create sync pipe: %s", strerror(errno));
-        g_free( (gpointer) argv[0]);
+        *msg = g_strdup_printf("Couldn't create sync pipe: %s", g_strerror(errno));
+        for (i = 0; argv[i] != NULL; i++) {
+            g_free( (gpointer) argv[i]);
+        }
         g_free(argv);
         return -1;
     }
@@ -851,10 +822,12 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
     /* Create a pipe for the child process to send us data */
     if (pipe(data_pipe) < 0) {
         /* Couldn't create the data pipe between parent and child. */
-        *msg = g_strdup_printf("Couldn't create data pipe: %s", strerror(errno));
+        *msg = g_strdup_printf("Couldn't create data pipe: %s", g_strerror(errno));
         ws_close(sync_pipe[PIPE_READ]);
         ws_close(sync_pipe[PIPE_WRITE]);
-        g_free( (gpointer) argv[0]);
+        for (i = 0; argv[i] != NULL; i++) {
+            g_free( (gpointer) argv[i]);
+        }
         g_free(argv);
         return -1;
     }
@@ -872,7 +845,7 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
         ws_close(sync_pipe[PIPE_WRITE]);
         execv(argv[0], (gpointer)argv);
         g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
-                   argv[0], strerror(errno));
+                   argv[0], g_strerror(errno));
         sync_pipe_errmsg_to_parent(2, errmsg, "");
 
         /* Exit with "_exit()", so that we don't close the connection
@@ -889,7 +862,9 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
     *message_read_fd = sync_pipe[PIPE_READ];
 #endif
 
-    g_free( (gpointer) argv[0]);  /* exename */
+    for (i = 0; argv[i] != NULL; i++) {
+        g_free( (gpointer) argv[i]);
+    }
 
     /* Parent process - read messages from the child process over the
        sync pipe. */
@@ -909,7 +884,7 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
 
     if (*fork_child == -1) {
         /* We couldn't even create the child process. */
-        *msg = g_strdup_printf("Couldn't create child process: %s", strerror(errno));
+        *msg = g_strdup_printf("Couldn't create child process: %s", g_strerror(errno));
         ws_close(*data_read_fd);
         ws_close(*message_read_fd);
         return -1;
@@ -921,14 +896,16 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
 }
 
 /*
- * Wait for dumpcap to finish.  On success, *msg is unchanged, and 0 is
- * returned.  On failure, *msg points to an error message for the
- * failure, and -1 is returned.  In the latter case, *msg must be
- * freed with g_free().
+ * Close the pipes we're using to read from dumpcap, and wait for it
+ * to exit.  On success, *msgp is unchanged, and the exit status of
+ * dumpcap is returned.  On failure (which includes "dumpcap exited
+ * due to being killed by a signal or an exception"), *msgp points
+ * to an error message for the failure, and -1 is returned.  In the
+ * latter case, *msgp must be freed with g_free().
  */
 static int
 sync_pipe_close_command(int *data_read_fd, int *message_read_fd,
-                        int *fork_child, gchar **msg)
+                        int *fork_child, gchar **msgp)
 {
     ws_close(*data_read_fd);
     if (message_read_fd != NULL)
@@ -939,7 +916,7 @@ sync_pipe_close_command(int *data_read_fd, int *message_read_fd,
     sync_pipe_kill(*fork_child);
 #endif
 
-    return sync_pipe_wait_for_child(*fork_child, msg);
+    return sync_pipe_wait_for_child(*fork_child, msgp);
 }
 
 /*
@@ -961,173 +938,173 @@ static int
 sync_pipe_run_command(const char** argv, gchar **data, gchar **primary_msg,
                       gchar **secondary_msg)
 {
-  gchar *msg;
-  int data_pipe_read_fd, sync_pipe_read_fd, fork_child, ret;
-  char *wait_msg;
-  gchar buffer[PIPE_BUF_SIZE+1];
-  int  nread;
-  char indicator;
-  int  primary_msg_len;
-  char *primary_msg_text;
-  int  secondary_msg_len;
-  char *secondary_msg_text;
-  char *combined_msg;
-  GString *data_buf = NULL;
-  int count;
-
-  ret = sync_pipe_open_command(argv, &data_pipe_read_fd, &sync_pipe_read_fd,
-                               &fork_child, &msg);
-  if (ret == -1) {
-    *primary_msg = msg;
-    *secondary_msg = NULL;
-    *data = NULL;
-    return -1;
-  }
-
-  /*
-   * We were able to set up to read dumpcap's output.  Do so.
-   *
-   * First, wait for an SP_ERROR_MSG message or SP_SUCCESS message.
-   */
-  nread = pipe_read_block(sync_pipe_read_fd, &indicator, SP_MAX_MSG_LEN,
-                          buffer, primary_msg);
-  if(nread <= 0) {
-    /* We got a read error from the sync pipe, or we got no data at
-       all from the sync pipe, so we're not going to be getting any
-       data or error message from the child process.  Pick up its
-       exit status, and complain.
-
-       We don't have to worry about killing the child, if the sync pipe
-       returned an error. Usually this error is caused as the child killed
-       itself while going down. Even in the rare cases that this isn't the
-       case, the child will get an error when writing to the broken pipe
-       the next time, cleaning itself up then. */
-    ret = sync_pipe_wait_for_child(fork_child, &wait_msg);
-    if(nread == 0) {
-      /* We got an EOF from the sync pipe.  That means that it exited
-         before giving us any data to read.  If ret is -1, we report
-         that as a bad exit (e.g., exiting due to a signal); otherwise,
-         we report it as a premature exit. */
-      if (ret == -1)
-        *primary_msg = wait_msg;
-      else
-        *primary_msg = g_strdup("Child dumpcap closed sync pipe prematurely");
-    } else {
-      /* We got an error from the sync pipe.  If ret is -1, report
-         both the sync pipe I/O error and the wait error. */
-      if (ret == -1) {
-        combined_msg = g_strdup_printf("%s\n\n%s", *primary_msg, wait_msg);
-        g_free(*primary_msg);
-        g_free(wait_msg);
-        *primary_msg = combined_msg;
-      }
+    gchar *msg;
+    int data_pipe_read_fd, sync_pipe_read_fd, fork_child, ret;
+    char *wait_msg;
+    gchar buffer[PIPE_BUF_SIZE+1];
+    int  nread;
+    char indicator;
+    int  primary_msg_len;
+    char *primary_msg_text;
+    int  secondary_msg_len;
+    char *secondary_msg_text;
+    char *combined_msg;
+    GString *data_buf = NULL;
+    int count;
+
+    ret = sync_pipe_open_command(argv, &data_pipe_read_fd, &sync_pipe_read_fd,
+                                 &fork_child, &msg);
+    if (ret == -1) {
+        *primary_msg = msg;
+        *secondary_msg = NULL;
+        *data = NULL;
+        return -1;
     }
-    *secondary_msg = NULL;
-
-    return -1;
-  }
 
-  /* we got a valid message block from the child, process it */
-  switch(indicator) {
-
-  case SP_ERROR_MSG:
     /*
-     * Error from dumpcap; there will be a primary message and a
-     * secondary message.
+     * We were able to set up to read dumpcap's output.  Do so.
+     *
+     * First, wait for an SP_ERROR_MSG message or SP_SUCCESS message.
      */
+    nread = pipe_read_block(sync_pipe_read_fd, &indicator, SP_MAX_MSG_LEN,
+                            buffer, primary_msg);
+    if(nread <= 0) {
+        /* We got a read error from the sync pipe, or we got no data at
+           all from the sync pipe, so we're not going to be getting any
+           data or error message from the child process.  Pick up its
+           exit status, and complain.
+
+           We don't have to worry about killing the child, if the sync pipe
+           returned an error. Usually this error is caused as the child killed
+           itself while going down. Even in the rare cases that this isn't the
+           case, the child will get an error when writing to the broken pipe
+           the next time, cleaning itself up then. */
+        ret = sync_pipe_wait_for_child(fork_child, &wait_msg);
+        if(nread == 0) {
+            /* We got an EOF from the sync pipe.  That means that it exited
+               before giving us any data to read.  If ret is -1, we report
+               that as a bad exit (e.g., exiting due to a signal); otherwise,
+               we report it as a premature exit. */
+            if (ret == -1)
+                *primary_msg = wait_msg;
+            else
+                *primary_msg = g_strdup("Child dumpcap closed sync pipe prematurely");
+        } else {
+            /* We got an error from the sync pipe.  If ret is -1, report
+               both the sync pipe I/O error and the wait error. */
+            if (ret == -1) {
+                combined_msg = g_strdup_printf("%s\n\n%s", *primary_msg, wait_msg);
+                g_free(*primary_msg);
+                g_free(wait_msg);
+                *primary_msg = combined_msg;
+            }
+        }
+        *secondary_msg = NULL;
 
-    /* convert primary message */
-    pipe_convert_header(buffer, 4, &indicator, &primary_msg_len);
-    primary_msg_text = buffer+4;
-    /* convert secondary message */
-    pipe_convert_header(primary_msg_text + primary_msg_len, 4, &indicator,
-                        &secondary_msg_len);
-    secondary_msg_text = primary_msg_text + primary_msg_len + 4;
-    /* the capture child will close the sync_pipe, nothing to do */
-
-    /*
-     * Pick up the child status.
-     */
-    ret = sync_pipe_close_command(&data_pipe_read_fd, &sync_pipe_read_fd,
-                                  &fork_child, &msg);
-    if (ret == -1) {
-      /*
-       * Child process failed unexpectedly, or wait failed; msg is the
-       * error message.
-       */
-      *primary_msg = msg;
-      *secondary_msg = NULL;
-    } else {
-      /*
-       * Child process failed, but returned the expected exit status.
-       * Return the messages it gave us, and indicate failure.
-       */
-      *primary_msg = g_strdup(primary_msg_text);
-      *secondary_msg = g_strdup(secondary_msg_text);
-      ret = -1;
-    }
-    *data = NULL;
-    break;
-
-  case SP_SUCCESS:
-    /* read the output from the command */
-    data_buf = g_string_new("");
-    while ((count = ws_read(data_pipe_read_fd, buffer, PIPE_BUF_SIZE)) > 0) {
-      buffer[count] = '\0';
-      g_string_append(data_buf, buffer);
+        return -1;
     }
 
-    /*
-     * Pick up the child status.
-     */
-    ret = sync_pipe_close_command(&data_pipe_read_fd, &sync_pipe_read_fd,
-                                  &fork_child, &msg);
-    if (ret == -1) {
-      /*
-       * Child process failed unexpectedly, or wait failed; msg is the
-       * error message.
-       */
-      *primary_msg = msg;
-      *secondary_msg = NULL;
-      g_string_free(data_buf, TRUE);
-      *data = NULL;
-    } else {
-      /*
-       * Child process succeeded.
-       */
-      *primary_msg = NULL;
-      *secondary_msg = NULL;
-      *data = data_buf->str;
-      g_string_free(data_buf, FALSE);
-    }
-    break;
+    /* we got a valid message block from the child, process it */
+    switch(indicator) {
 
-  default:
-    /*
-     * Pick up the child status.
-     */
-    ret = sync_pipe_close_command(&data_pipe_read_fd, &sync_pipe_read_fd,
-                                  &fork_child, &msg);
-    if (ret == -1) {
-      /*
-       * Child process failed unexpectedly, or wait failed; msg is the
-       * error message.
-       */
-      *primary_msg = msg;
-      *secondary_msg = NULL;
-    } else {
-      /*
-       * Child process returned an unknown status.
-       */
-      *primary_msg = g_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
-                                     indicator);
-      *secondary_msg = NULL;
-      ret = -1;
+    case SP_ERROR_MSG:
+        /*
+         * Error from dumpcap; there will be a primary message and a
+         * secondary message.
+         */
+
+        /* convert primary message */
+        pipe_convert_header(buffer, 4, &indicator, &primary_msg_len);
+        primary_msg_text = buffer+4;
+        /* convert secondary message */
+        pipe_convert_header(primary_msg_text + primary_msg_len, 4, &indicator,
+                            &secondary_msg_len);
+        secondary_msg_text = primary_msg_text + primary_msg_len + 4;
+        /* the capture child will close the sync_pipe, nothing to do */
+
+        /*
+         * Pick up the child status.
+         */
+        ret = sync_pipe_close_command(&data_pipe_read_fd, &sync_pipe_read_fd,
+                                      &fork_child, &msg);
+        if (ret == -1) {
+            /*
+             * Child process failed unexpectedly, or wait failed; msg is the
+             * error message.
+             */
+            *primary_msg = msg;
+            *secondary_msg = NULL;
+        } else {
+            /*
+             * Child process failed, but returned the expected exit status.
+             * Return the messages it gave us, and indicate failure.
+             */
+            *primary_msg = g_strdup(primary_msg_text);
+            *secondary_msg = g_strdup(secondary_msg_text);
+            ret = -1;
+        }
+        *data = NULL;
+        break;
+
+    case SP_SUCCESS:
+        /* read the output from the command */
+        data_buf = g_string_new("");
+        while ((count = ws_read(data_pipe_read_fd, buffer, PIPE_BUF_SIZE)) > 0) {
+            buffer[count] = '\0';
+            g_string_append(data_buf, buffer);
+        }
+
+        /*
+         * Pick up the child status.
+         */
+        ret = sync_pipe_close_command(&data_pipe_read_fd, &sync_pipe_read_fd,
+                                      &fork_child, &msg);
+        if (ret == -1) {
+            /*
+             * Child process failed unexpectedly, or wait failed; msg is the
+             * error message.
+             */
+            *primary_msg = msg;
+            *secondary_msg = NULL;
+            g_string_free(data_buf, TRUE);
+            *data = NULL;
+        } else {
+            /*
+             * Child process succeeded.
+             */
+            *primary_msg = NULL;
+            *secondary_msg = NULL;
+            *data = data_buf->str;
+            g_string_free(data_buf, FALSE);
+        }
+        break;
+
+    default:
+        /*
+         * Pick up the child status.
+         */
+        ret = sync_pipe_close_command(&data_pipe_read_fd, &sync_pipe_read_fd,
+                                      &fork_child, &msg);
+        if (ret == -1) {
+            /*
+             * Child process failed unexpectedly, or wait failed; msg is the
+             * error message.
+             */
+            *primary_msg = msg;
+            *secondary_msg = NULL;
+        } else {
+            /*
+             * Child process returned an unknown status.
+             */
+            *primary_msg = g_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
+                                           indicator);
+            *secondary_msg = NULL;
+            ret = -1;
+        }
+        *data = NULL;
+        break;
     }
-    *data = NULL;
-    break;
-  }
-  return ret;
+    return ret;
 }
 
 /*
@@ -1226,147 +1203,147 @@ sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
 int
 sync_interface_stats_open(int *data_read_fd, int *fork_child, gchar **msg)
 {
-  int argc;
-  const char **argv;
-  int message_read_fd, ret;
-  char *wait_msg;
-  gchar buffer[PIPE_BUF_SIZE+1];
-  int  nread;
-  char indicator;
-  int  primary_msg_len;
-  char *primary_msg_text;
-  int  secondary_msg_len;
-  char *secondary_msg_text;
-  char *combined_msg;
-
-  g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_interface_stats_open");
-
-  argv = init_pipe_args(&argc);
-
-  if (!argv) {
-    *msg = g_strdup("We don't know where to find dumpcap.");
-    return -1;
-  }
-
-  /* Ask for the interface statistics */
-  argv = sync_pipe_add_arg(argv, &argc, "-S");
+    int argc;
+    const char **argv;
+    int message_read_fd, ret;
+    char *wait_msg;
+    gchar buffer[PIPE_BUF_SIZE+1];
+    int  nread;
+    char indicator;
+    int  primary_msg_len;
+    char *primary_msg_text;
+    int  secondary_msg_len;
+    /*char *secondary_msg_text;*/
+    char *combined_msg;
+
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_interface_stats_open");
 
-#ifndef DEBUG_CHILD
-  argv = sync_pipe_add_arg(argv, &argc, "-Z");
-  argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
-#endif
-  ret = sync_pipe_open_command(argv, data_read_fd, &message_read_fd,
-                                 fork_child, msg);
-  if (ret == -1)
-    return -1;
-
-  /*
-   * We were able to set up to read dumpcap's output.  Do so.
-   *
-   * First, wait for an SP_ERROR_MSG message or SP_SUCCESS message.
-   */
-  nread = pipe_read_block(message_read_fd, &indicator, SP_MAX_MSG_LEN,
-                          buffer, msg);
-  if(nread <= 0) {
-    /* We got a read error from the sync pipe, or we got no data at
-       all from the sync pipe, so we're not going to be getting any
-       data or error message from the child process.  Pick up its
-       exit status, and complain.
-
-       We don't have to worry about killing the child, if the sync pipe
-       returned an error. Usually this error is caused as the child killed
-       itself while going down. Even in the rare cases that this isn't the
-       case, the child will get an error when writing to the broken pipe
-       the next time, cleaning itself up then. */
-    ret = sync_pipe_wait_for_child(*fork_child, &wait_msg);
-    if(nread == 0) {
-      /* We got an EOF from the sync pipe.  That means that it exited
-         before giving us any data to read.  If ret is -1, we report
-         that as a bad exit (e.g., exiting due to a signal); otherwise,
-         we report it as a premature exit. */
-      if (ret == -1)
-        *msg = wait_msg;
-      else
-        *msg = g_strdup("Child dumpcap closed sync pipe prematurely");
-    } else {
-      /* We got an error from the sync pipe.  If ret is -1, report
-         both the sync pipe I/O error and the wait error. */
-      if (ret == -1) {
-        combined_msg = g_strdup_printf("%s\n\n%s", *msg, wait_msg);
-        g_free(*msg);
-        g_free(wait_msg);
-        *msg = combined_msg;
-      }
+    argv = init_pipe_args(&argc);
+
+    if (!argv) {
+        *msg = g_strdup("We don't know where to find dumpcap.");
+        return -1;
     }
 
-    return -1;
-  }
+    /* Ask for the interface statistics */
+    argv = sync_pipe_add_arg(argv, &argc, "-S");
 
-  /* we got a valid message block from the child, process it */
-  switch(indicator) {
+#ifndef DEBUG_CHILD
+    argv = sync_pipe_add_arg(argv, &argc, "-Z");
+    argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
+#endif
+    ret = sync_pipe_open_command(argv, data_read_fd, &message_read_fd,
+                                 fork_child, msg);
+    if (ret == -1)
+        return -1;
 
-  case SP_ERROR_MSG:
     /*
-     * Error from dumpcap; there will be a primary message and a
-     * secondary message.
+     * We were able to set up to read dumpcap's output.  Do so.
+     *
+     * First, wait for an SP_ERROR_MSG message or SP_SUCCESS message.
      */
+    nread = pipe_read_block(message_read_fd, &indicator, SP_MAX_MSG_LEN,
+                            buffer, msg);
+    if(nread <= 0) {
+        /* We got a read error from the sync pipe, or we got no data at
+           all from the sync pipe, so we're not going to be getting any
+           data or error message from the child process.  Pick up its
+           exit status, and complain.
+
+           We don't have to worry about killing the child, if the sync pipe
+           returned an error. Usually this error is caused as the child killed
+           itself while going down. Even in the rare cases that this isn't the
+           case, the child will get an error when writing to the broken pipe
+           the next time, cleaning itself up then. */
+        ret = sync_pipe_wait_for_child(*fork_child, &wait_msg);
+        if(nread == 0) {
+            /* We got an EOF from the sync pipe.  That means that it exited
+               before giving us any data to read.  If ret is -1, we report
+               that as a bad exit (e.g., exiting due to a signal); otherwise,
+               we report it as a premature exit. */
+            if (ret == -1)
+                *msg = wait_msg;
+            else
+                *msg = g_strdup("Child dumpcap closed sync pipe prematurely");
+        } else {
+            /* We got an error from the sync pipe.  If ret is -1, report
+               both the sync pipe I/O error and the wait error. */
+            if (ret == -1) {
+                combined_msg = g_strdup_printf("%s\n\n%s", *msg, wait_msg);
+                g_free(*msg);
+                g_free(wait_msg);
+                *msg = combined_msg;
+            }
+        }
 
-    /* convert primary message */
-    pipe_convert_header(buffer, 4, &indicator, &primary_msg_len);
-    primary_msg_text = buffer+4;
-    /* convert secondary message */
-    pipe_convert_header(primary_msg_text + primary_msg_len, 4, &indicator,
-                        &secondary_msg_len);
-    secondary_msg_text = primary_msg_text + primary_msg_len + 4;
-    /* the capture child will close the sync_pipe, nothing to do */
-
-    /*
-     * Pick up the child status.
-     */
-    ret = sync_pipe_close_command(data_read_fd, &message_read_fd,
-                                  fork_child, msg);
-    if (ret == -1) {
-      /*
-       * Child process failed unexpectedly, or wait failed; msg is the
-       * error message.
-       */
-    } else {
-      /*
-       * Child process failed, but returned the expected exit status.
-       * Return the messages it gave us, and indicate failure.
-       */
-      *msg = g_strdup(primary_msg_text);
-      ret = -1;
+        return -1;
     }
-    break;
 
-  case SP_SUCCESS:
-    /* Close the message pipe. */
-    ws_close(message_read_fd);
-    break;
+    /* we got a valid message block from the child, process it */
+    switch(indicator) {
 
-  default:
-    /*
-     * Pick up the child status.
-     */
-    ret = sync_pipe_close_command(data_read_fd, &message_read_fd,
-                                  fork_child, msg);
-    if (ret == -1) {
-      /*
-       * Child process failed unexpectedly, or wait failed; msg is the
-       * error message.
-       */
-    } else {
-      /*
-       * Child process returned an unknown status.
-       */
-      *msg = g_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
-                             indicator);
-      ret = -1;
+    case SP_ERROR_MSG:
+        /*
+         * Error from dumpcap; there will be a primary message and a
+         * secondary message.
+         */
+
+        /* convert primary message */
+        pipe_convert_header(buffer, 4, &indicator, &primary_msg_len);
+        primary_msg_text = buffer+4;
+        /* convert secondary message */
+        pipe_convert_header(primary_msg_text + primary_msg_len, 4, &indicator,
+                            &secondary_msg_len);
+        /*secondary_msg_text = primary_msg_text + primary_msg_len + 4;*/
+        /* the capture child will close the sync_pipe, nothing to do */
+
+        /*
+         * Pick up the child status.
+         */
+        ret = sync_pipe_close_command(data_read_fd, &message_read_fd,
+                                      fork_child, msg);
+        if (ret == -1) {
+            /*
+             * Child process failed unexpectedly, or wait failed; msg is the
+             * error message.
+             */
+        } else {
+            /*
+             * Child process failed, but returned the expected exit status.
+             * Return the messages it gave us, and indicate failure.
+             */
+            *msg = g_strdup(primary_msg_text);
+            ret = -1;
+        }
+        break;
+
+    case SP_SUCCESS:
+        /* Close the message pipe. */
+        ws_close(message_read_fd);
+        break;
+
+    default:
+        /*
+         * Pick up the child status.
+         */
+        ret = sync_pipe_close_command(data_read_fd, &message_read_fd,
+                                      fork_child, msg);
+        if (ret == -1) {
+            /*
+             * Child process failed unexpectedly, or wait failed; msg is the
+             * error message.
+             */
+        } else {
+            /*
+             * Child process returned an unknown status.
+             */
+            *msg = g_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
+                                   indicator);
+            ret = -1;
+        }
+        break;
     }
-    break;
-  }
-  return ret;
+    return ret;
 }
 
 /* Close down the stats process */
@@ -1399,9 +1376,9 @@ pipe_read_bytes(int pipe_fd, char *bytes, int required, char **msg)
             error = errno;
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
                   "read from pipe %d: error(%u): %s", pipe_fd, error,
-                  strerror(error));
+                  g_strerror(error));
             *msg = g_strdup_printf("Error reading from sync pipe: %s",
-                                   strerror(error));
+                                   g_strerror(error));
             return newly;
         }
 
@@ -1460,7 +1437,7 @@ sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max) {
         } else if (newly < 0) {
             /* error */
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-                  "read from pipe %d: error(%u): %s", pipe_fd, errno, strerror(errno));
+                  "read from pipe %d: error(%u): %s", pipe_fd, errno, g_strerror(errno));
             return newly;
         } else if (bytes[offset] == '\n') {
             break;
@@ -1499,12 +1476,12 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
     /* read header (indicator and 3-byte length) */
     newly = pipe_read_bytes(pipe_fd, header, 4, err_msg);
     if(newly != 4) {
-       if (newly == 0) {
-           /*
-            * Immediate EOF; if the capture child exits normally, this
-            * is an "I'm done" indication, so don't report it as an
-            * error.
-            */
+        if (newly == 0) {
+            /*
+             * Immediate EOF; if the capture child exits normally, this
+             * is an "I'm done" indication, so don't report it as an
+             * error.
+             */
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
                   "read %d got an EOF", pipe_fd);
             return 0;
@@ -1513,8 +1490,8 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
               "read %d failed to read header: %u", pipe_fd, newly);
         if (newly != -1) {
             /*
-            * Short read, but not an immediate EOF.
-            */
+             * Short read, but not an immediate EOF.
+             */
             *err_msg = g_strdup_printf("Premature EOF reading from sync pipe: got only %d bytes",
                                        newly);
         }
@@ -1549,10 +1526,10 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
     /* read the actual block data */
     newly = pipe_read_bytes(pipe_fd, msg, required, err_msg);
     if(newly != required) {
-       if (newly != -1) {
+        if (newly != -1) {
             *err_msg = g_strdup_printf("Unknown message from dumpcap, try to show it as a string: %s",
                                        msg);
-       }
+        }
         return -1;
     }
 
@@ -1571,178 +1548,201 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
 static gboolean
 sync_pipe_input_cb(gint source, gpointer user_data)
 {
-  capture_options *capture_opts = (capture_options *)user_data;
-  int  ret;
-  char buffer[SP_MAX_MSG_LEN+1];
-  int  nread;
-  char indicator;
-  int  primary_len;
-  char *primary_msg;
-  int  secondary_len;
-  char *secondary_msg;
-  char *wait_msg, *combined_msg;
-
-  nread = pipe_read_block(source, &indicator, SP_MAX_MSG_LEN, buffer,
-                          &primary_msg);
-  if(nread <= 0) {
-    /* We got a read error, or a bad message, or an EOF, from the sync pipe.
-
-       If we got a read error or a bad message, nread is -1 and
-       primary_msg is set to point to an error message.  We don't
-       have to worry about killing the child; usually this error
-       is caused as the child killed  itself while going down.
-       Even in the rare cases that this isn't the case, the child
-       will get an error when writing to the broken pipe the next time,
-       cleaning itself up then.
-
-       If we got an EOF, nread is 0 and primary_msg isn't set.  This
-       is an indication that the capture is finished. */
-    ret = sync_pipe_wait_for_child(capture_opts->fork_child, &wait_msg);
-    if(nread == 0) {
-      /* We got an EOF from the sync pipe.  That means that the capture
-         child exited, and not in the middle of a message; we treat
-         that as an indication that it's done, and only report an
-         error if ret is -1, in which case wait_msg is the error
-         message. */
-      if (ret == -1)
-        primary_msg = wait_msg;
-    } else {
-      /* We got an error from the sync pipe.  If ret is -1, report
-         both the sync pipe I/O error and the wait error. */
-      if (ret == -1) {
-        combined_msg = g_strdup_printf("%s\n\n%s", primary_msg, wait_msg);
-        g_free(primary_msg);
-        g_free(wait_msg);
-        primary_msg = combined_msg;
-      }
-    }
+    capture_options *capture_opts = (capture_options *)user_data;
+    int  ret;
+    char buffer[SP_MAX_MSG_LEN+1];
+    int  nread;
+    char indicator;
+    int  primary_len;
+    char *primary_msg;
+    int  secondary_len;
+    char *secondary_msg;
+    char *wait_msg, *combined_msg;
+
+    nread = pipe_read_block(source, &indicator, SP_MAX_MSG_LEN, buffer,
+                            &primary_msg);
+    if(nread <= 0) {
+        /* We got a read error, or a bad message, or an EOF, from the sync pipe.
+
+           If we got a read error or a bad message, nread is -1 and
+           primary_msg is set to point to an error message.  We don't
+           have to worry about killing the child; usually this error
+           is caused as the child killed  itself while going down.
+           Even in the rare cases that this isn't the case, the child
+           will get an error when writing to the broken pipe the next time,
+           cleaning itself up then.
+
+           If we got an EOF, nread is 0 and primary_msg isn't set.  This
+           is an indication that the capture is finished. */
+        ret = sync_pipe_wait_for_child(capture_opts->fork_child, &wait_msg);
+        if(nread == 0) {
+            /* We got an EOF from the sync pipe.  That means that the capture
+               child exited, and not in the middle of a message; we treat
+               that as an indication that it's done, and only report an
+               error if ret is -1, in which case wait_msg is the error
+               message. */
+            if (ret == -1)
+                primary_msg = wait_msg;
+        } else {
+            /* We got an error from the sync pipe.  If ret is -1, report
+               both the sync pipe I/O error and the wait error. */
+            if (ret == -1) {
+                combined_msg = g_strdup_printf("%s\n\n%s", primary_msg, wait_msg);
+                g_free(primary_msg);
+                g_free(wait_msg);
+                primary_msg = combined_msg;
+            }
+        }
 
-    /* No more child process. */
-    capture_opts->fork_child = -1;
-    capture_opts->fork_child_status = ret;
+        /* No more child process. */
+        capture_opts->fork_child = -1;
+        capture_opts->fork_child_status = ret;
 
 #ifdef _WIN32
-    ws_close(capture_opts->signal_pipe_write_fd);
+        ws_close(capture_opts->signal_pipe_write_fd);
 #endif
-    capture_input_closed(capture_opts, primary_msg);
-    g_free(primary_msg);
-    return FALSE;
-  }
-
-  /* we got a valid message block from the child, process it */
-  switch(indicator) {
-  case SP_FILE:
-    if(!capture_input_new_file(capture_opts, buffer)) {
-      g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: file failed, closing capture");
-
-      /* We weren't able to open the new capture file; user has been
-         alerted. Close the sync pipe. */
-      ws_close(source);
-
-      /* the child has send us a filename which we couldn't open.
-         this probably means, the child is creating files faster than we can handle it.
-         this should only be the case for very fast file switches
-         we can't do much more than telling the child to stop
-         (this is the "emergency brake" if user e.g. wants to switch files every second) */
-      sync_pipe_stop(capture_opts);
+        capture_input_closed(capture_opts, primary_msg);
+        g_free(primary_msg);
+        return FALSE;
+    }
+
+    /* we got a valid message block from the child, process it */
+    switch(indicator) {
+    case SP_FILE:
+        if(!capture_input_new_file(capture_opts, buffer)) {
+            g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: file failed, closing capture");
+
+            /* We weren't able to open the new capture file; user has been
+               alerted. Close the sync pipe. */
+            ws_close(source);
+
+            /* The child has sent us a filename which we couldn't open.
+
+               This could mean that the child is creating files faster
+              than we can handle it.  (XXX - why would that result in
+              a failure to open the file?)
+
+               That should only be the case for very fast file switches;
+               We can't do much more than telling the child to stop.
+               (This is the "emergency brake" if the user e.g. wants to
+              switch files every second).
+
+               This can also happen if the user specified "-", meaning
+               "standard output", as the capture file. */
+            sync_pipe_stop(capture_opts);
+            capture_input_closed(capture_opts, NULL);
+            return FALSE;
+        }
+        break;
+    case SP_PACKET_COUNT:
+        nread = atoi(buffer);
+        g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", nread);
+        capture_input_new_packets(capture_opts, nread);
+        break;
+    case SP_ERROR_MSG:
+        /* convert primary message */
+        pipe_convert_header(buffer, 4, &indicator, &primary_len);
+        primary_msg = buffer+4;
+        /* convert secondary message */
+        pipe_convert_header(primary_msg + primary_len, 4, &indicator, &secondary_len);
+        secondary_msg = primary_msg + primary_len + 4;
+        /* message output */
+        capture_input_error_message(capture_opts, primary_msg, secondary_msg);
+        /* the capture child will close the sync_pipe, nothing to do for now */
+        /* (an error message doesn't mean we have to stop capturing) */
+        break;
+    case SP_BAD_FILTER: {
+        char *ch;
+        int index;
+
+        ch = strtok(buffer, ":");
+        index = (int)strtol(ch, NULL, 10);
+        ch = strtok(NULL, ":");
+        capture_input_cfilter_error_message(capture_opts, index, ch);
+         /* the capture child will close the sync_pipe, nothing to do for now */
+         break;
+        }
+    case SP_DROPS:
+        capture_input_drops(capture_opts, (guint32)strtoul(buffer, NULL, 10));
+        break;
+    default:
+        g_assert_not_reached();
     }
-    break;
-  case SP_PACKET_COUNT:
-    nread = atoi(buffer);
-    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", nread);
-    capture_input_new_packets(capture_opts, nread);
-    break;
-  case SP_ERROR_MSG:
-    /* convert primary message */
-    pipe_convert_header(buffer, 4, &indicator, &primary_len);
-    primary_msg = buffer+4;
-    /* convert secondary message */
-    pipe_convert_header(primary_msg + primary_len, 4, &indicator, &secondary_len);
-    secondary_msg = primary_msg + primary_len + 4;
-    /* message output */
-    capture_input_error_message(capture_opts, primary_msg, secondary_msg);
-    /* the capture child will close the sync_pipe, nothing to do for now */
-    /* (an error message doesn't mean we have to stop capturing) */
-    break;
-  case SP_BAD_FILTER:
-    capture_input_cfilter_error_message(capture_opts, buffer);
-    /* the capture child will close the sync_pipe, nothing to do for now */
-    break;
-  case SP_DROPS:
-    capture_input_drops(capture_opts, (guint32)strtoul(buffer, NULL, 10));
-    break;
-  default:
-    g_assert_not_reached();
-  }
-
-  return TRUE;
+
+    return TRUE;
 }
 
 
 
-/* the child process is going down, wait until it's completely terminated */
+/*
+ * dumpcap is exiting; wait for it to exit.  On success, *msgp is
+ * unchanged, and the exit status of dumpcap is returned.  On
+ * failure (which includes "dumpcap exited due to being killed by
+ * a signal or an exception"), *msgp points to an error message
+ * for the failure, and -1 is returned.  In the latter case, *msgp
+ * must be freed with g_free().
+ */
 static int
 sync_pipe_wait_for_child(int fork_child, gchar **msgp)
 {
-  int fork_child_status;
-  int ret;
+    int fork_child_status;
+    int ret;
 
-  g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: wait till child closed");
-  g_assert(fork_child != -1);
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: wait till child closed");
+    g_assert(fork_child != -1);
 
-  *msgp = NULL; /* assume no error */
-  ret = 0;
+    *msgp = NULL; /* assume no error */
 #ifdef _WIN32
-  if (_cwait(&fork_child_status, fork_child, _WAIT_CHILD) == -1) {
-    *msgp = g_strdup_printf("Error from cwait(): %s", strerror(errno));
-    ret = -1;
-  } else {
-    /*
-     * The child exited; return its exit status.  Do not treat this as
-     * an error.
-     */
-    ret = fork_child_status;
-    if ((fork_child_status & 0xC0000000) == ERROR_SEVERITY_ERROR) {
-      /* Probably an exception code */
-      *msgp = g_strdup_printf("Child dumpcap process died: %s",
-                              win32strexception(fork_child_status));
-      ret = -1;
+    if (_cwait(&fork_child_status, fork_child, _WAIT_CHILD) == -1) {
+        *msgp = g_strdup_printf("Error from cwait(): %s", g_strerror(errno));
+        ret = -1;
+    } else {
+        /*
+         * The child exited; return its exit status.  Do not treat this as
+         * an error.
+         */
+        ret = fork_child_status;
+        if ((fork_child_status & 0xC0000000) == ERROR_SEVERITY_ERROR) {
+            /* Probably an exception code */
+            *msgp = g_strdup_printf("Child dumpcap process died: %s",
+                                    win32strexception(fork_child_status));
+            ret = -1;
+        }
     }
-  }
 #else
-  if (waitpid(fork_child, &fork_child_status, 0) != -1) {
-    if (WIFEXITED(fork_child_status)) {
-      /*
-       * The child exited; return its exit status.  Do not treat this as
-       * an error.
-       */
-      ret = WEXITSTATUS(fork_child_status);
-    } else if (WIFSTOPPED(fork_child_status)) {
-      /* It stopped, rather than exiting.  "Should not happen." */
-      *msgp = g_strdup_printf("Child dumpcap process stopped: %s",
-                              sync_pipe_signame(WSTOPSIG(fork_child_status)));
-      ret = -1;
-    } else if (WIFSIGNALED(fork_child_status)) {
-      /* It died with a signal. */
-      *msgp = g_strdup_printf("Child dumpcap process died: %s%s",
-                              sync_pipe_signame(WTERMSIG(fork_child_status)),
-                              WCOREDUMP(fork_child_status) ? " - core dumped" : "");
-      ret = -1;
+    if (waitpid(fork_child, &fork_child_status, 0) != -1) {
+        if (WIFEXITED(fork_child_status)) {
+            /*
+             * The child exited; return its exit status.  Do not treat this as
+             * an error.
+             */
+            ret = WEXITSTATUS(fork_child_status);
+        } else if (WIFSTOPPED(fork_child_status)) {
+            /* It stopped, rather than exiting.  "Should not happen." */
+            *msgp = g_strdup_printf("Child dumpcap process stopped: %s",
+                                    sync_pipe_signame(WSTOPSIG(fork_child_status)));
+            ret = -1;
+        } else if (WIFSIGNALED(fork_child_status)) {
+            /* It died with a signal. */
+            *msgp = g_strdup_printf("Child dumpcap process died: %s%s",
+                                    sync_pipe_signame(WTERMSIG(fork_child_status)),
+                                    WCOREDUMP(fork_child_status) ? " - core dumped" : "");
+            ret = -1;
+        } else {
+            /* What?  It had to either have exited, or stopped, or died with
+               a signal; what happened here? */
+            *msgp = g_strdup_printf("Bad status from waitpid(): %#o",
+                                    fork_child_status);
+            ret = -1;
+        }
     } else {
-      /* What?  It had to either have exited, or stopped, or died with
-         a signal; what happened here? */
-      *msgp = g_strdup_printf("Bad status from waitpid(): %#o",
-                              fork_child_status);
-      ret = -1;
+        *msgp = g_strdup_printf("Error from waitpid(): %s", g_strerror(errno));
+        ret = -1;
     }
-  } else {
-    *msgp = g_strdup_printf("Error from waitpid(): %s", strerror(errno));
-    ret = -1;
-  }
 #endif
 
-  g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: capture child closed");
-  return ret;
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: capture child closed");
+    return ret;
 }
 
 
@@ -1751,94 +1751,94 @@ sync_pipe_wait_for_child(int fork_child, gchar **msgp)
 static const char *
 sync_pipe_signame(int sig)
 {
-  const char *sigmsg;
-  static char sigmsg_buf[6+1+3+1];
+    const char *sigmsg;
+    static char sigmsg_buf[6+1+3+1];
 
-  switch (sig) {
+    switch (sig) {
 
-  case SIGHUP:
-    sigmsg = "Hangup";
-    break;
+    case SIGHUP:
+        sigmsg = "Hangup";
+        break;
 
-  case SIGINT:
-    sigmsg = "Interrupted";
-    break;
+    case SIGINT:
+        sigmsg = "Interrupted";
+        break;
 
-  case SIGQUIT:
-    sigmsg = "Quit";
-    break;
+    case SIGQUIT:
+        sigmsg = "Quit";
+        break;
 
-  case SIGILL:
-    sigmsg = "Illegal instruction";
-    break;
+    case SIGILL:
+        sigmsg = "Illegal instruction";
+        break;
 
-  case SIGTRAP:
-    sigmsg = "Trace trap";
-    break;
+    case SIGTRAP:
+        sigmsg = "Trace trap";
+        break;
 
-  case SIGABRT:
-    sigmsg = "Abort";
-    break;
+    case SIGABRT:
+        sigmsg = "Abort";
+        break;
 
-  case SIGFPE:
-    sigmsg = "Arithmetic exception";
-    break;
+    case SIGFPE:
+        sigmsg = "Arithmetic exception";
+        break;
 
-  case SIGKILL:
-    sigmsg = "Killed";
-    break;
+    case SIGKILL:
+        sigmsg = "Killed";
+        break;
 
-  case SIGBUS:
-    sigmsg = "Bus error";
-    break;
+    case SIGBUS:
+        sigmsg = "Bus error";
+        break;
 
-  case SIGSEGV:
-    sigmsg = "Segmentation violation";
-    break;
+    case SIGSEGV:
+        sigmsg = "Segmentation violation";
+        break;
 
-  /* http://metalab.unc.edu/pub/Linux/docs/HOWTO/GCC-HOWTO
-     Linux is POSIX compliant.  These are not POSIX-defined signals ---
-     ISO/IEC 9945-1:1990 (IEEE Std 1003.1-1990), paragraph B.3.3.1.1 sez:
+        /* http://metalab.unc.edu/pub/Linux/docs/HOWTO/GCC-HOWTO
+           Linux is POSIX compliant.  These are not POSIX-defined signals ---
+           ISO/IEC 9945-1:1990 (IEEE Std 1003.1-1990), paragraph B.3.3.1.1 sez:
 
-        ``The signals SIGBUS, SIGEMT, SIGIOT, SIGTRAP, and SIGSYS
-        were omitted from POSIX.1 because their behavior is
-        implementation dependent and could not be adequately catego-
-        rized.  Conforming implementations may deliver these sig-
-        nals, but must document the circumstances under which they
-        are delivered and note any restrictions concerning their
-        delivery.''
+           ``The signals SIGBUS, SIGEMT, SIGIOT, SIGTRAP, and SIGSYS
+           were omitted from POSIX.1 because their behavior is
+           implementation dependent and could not be adequately catego-
+           rized.  Conforming implementations may deliver these sig-
+           nals, but must document the circumstances under which they
+           are delivered and note any restrictions concerning their
+           delivery.''
 
-     So we only check for SIGSYS on those systems that happen to
-     implement them (a system can be POSIX-compliant and implement
-     them, it's just that POSIX doesn't *require* a POSIX-compliant
-     system to implement them).
-   */
+           So we only check for SIGSYS on those systems that happen to
+           implement them (a system can be POSIX-compliant and implement
+           them, it's just that POSIX doesn't *require* a POSIX-compliant
+           system to implement them).
+        */
 
 #ifdef SIGSYS
-  case SIGSYS:
-    sigmsg = "Bad system call";
-    break;
+    case SIGSYS:
+        sigmsg = "Bad system call";
+        break;
 #endif
 
-  case SIGPIPE:
-    sigmsg = "Broken pipe";
-    break;
-
-  case SIGALRM:
-    sigmsg = "Alarm clock";
-    break;
-
-  case SIGTERM:
-    sigmsg = "Terminated";
-    break;
-
-  default:
-    /* Returning a static buffer is ok in the context we use it here */
-    g_snprintf(sigmsg_buf, sizeof sigmsg_buf, "Signal %d", sig);
-    sigmsg = sigmsg_buf;
-    break;
-  }
-  return sigmsg;
+    case SIGPIPE:
+        sigmsg = "Broken pipe";
+        break;
+
+    case SIGALRM:
+        sigmsg = "Alarm clock";
+        break;
+
+    case SIGTERM:
+        sigmsg = "Terminated";
+        break;
+
+    default:
+        /* Returning a static buffer is ok in the context we use it here */
+        g_snprintf(sigmsg_buf, sizeof sigmsg_buf, "Signal %d", sig);
+        sigmsg = sigmsg_buf;
+        break;
+    }
+    return sigmsg;
 }
 #endif
 
@@ -1860,7 +1860,7 @@ signal_pipe_capquit_to_child(capture_options *capture_opts)
     ret = write(capture_opts->signal_pipe_write_fd, quit_msg, sizeof quit_msg);
     if(ret == -1) {
         g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
-              "signal_pipe_capquit_to_child: %d header: error %s", capture_opts->signal_pipe_write_fd, strerror(errno));
+              "signal_pipe_capquit_to_child: %d header: error %s", capture_opts->signal_pipe_write_fd, g_strerror(errno));
     }
 }
 #endif
@@ -1871,45 +1871,45 @@ void
 sync_pipe_stop(capture_options *capture_opts)
 {
 #ifdef _WIN32
-  int count;
-  DWORD childstatus;
-  gboolean terminate = TRUE;
+    int count;
+    DWORD childstatus;
+    gboolean terminate = TRUE;
 #endif
 
-  if (capture_opts->fork_child != -1) {
+    if (capture_opts->fork_child != -1) {
 #ifndef _WIN32
-    /* send the SIGINT signal to close the capture child gracefully. */
-    int sts = kill(capture_opts->fork_child, SIGINT);
-    if (sts != 0) {
-        g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
-              "Sending SIGINT to child failed: %s\n", strerror(errno));
-    }
+        /* send the SIGINT signal to close the capture child gracefully. */
+        int sts = kill(capture_opts->fork_child, SIGINT);
+        if (sts != 0) {
+            g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
+                  "Sending SIGINT to child failed: %s\n", g_strerror(errno));
+        }
 #else
 #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);
-    }
+        /* 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);
-    }
+        /* 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
-  }
+    }
 }
 
 
@@ -1922,7 +1922,7 @@ sync_pipe_kill(int fork_child)
         int sts = kill(fork_child, SIGTERM);    /* SIGTERM so it can clean up if necessary */
         if (sts != 0) {
             g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
-                  "Sending SIGTERM to child failed: %s\n", strerror(errno));
+                  "Sending SIGTERM to child failed: %s\n", g_strerror(errno));
         }
 #else
         /* Remark: This is not the preferred method of closing a process!