Make the sync pipe the standard error, not the standard output, of
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 10 Oct 2007 01:31:36 +0000 (01:31 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 10 Oct 2007 01:31:36 +0000 (01:31 +0000)
dumpcap, when using it as a capture child; leave the standard output
alone, in case tshark was told to write the capture to the standard
error.

Get rid of the argument to the "-Z" option to dumpcap; it might not work
on Windows.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@23124 f5534014-38df-0310-8fa8-9805f1628bb7

capture_sync.c
dumpcap.c

index a31f0194974c066417c883a05895b003718ef80d..04d3244101e44a6c68d64c9c2abc11e245173bae 100644 (file)
@@ -354,7 +354,6 @@ sync_pipe_start(capture_options *capture_opts) {
     /* dumpcap should be running in capture child mode (hidden feature) */
 #ifndef DEBUG_CHILD
     argv = sync_pipe_add_arg(argv, &argc, "-Z");
-    argv = sync_pipe_add_arg(argv, &argc, "1");
 #endif
 
 #ifdef _WIN32
@@ -412,7 +411,7 @@ sync_pipe_start(capture_options *capture_opts) {
     si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
     si.wShowWindow  = SW_HIDE;  /* this hides the console window */
     si.hStdInput = signal_pipe_read;
-    si.hStdOutput = sync_pipe_write;
+    si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
     si.hStdError = sync_pipe_write;
     /*si.hStdError = (HANDLE) _get_osfhandle(2);*/
 #endif
@@ -466,7 +465,7 @@ sync_pipe_start(capture_options *capture_opts) {
        * Child process - run dumpcap with the right arguments to make
        * it just capture with the specified capture parameters
        */
-      eth_close(1);
+      eth_close(2);
       dup(sync_pipe[PIPE_WRITE]);
       eth_close(sync_pipe[PIPE_READ]);
       execv(argv[0], (gpointer)argv);
@@ -805,7 +804,6 @@ sync_interface_list_open(gchar **msg) {
     /* dumpcap should be running in capture child mode (hidden feature) */
 #ifndef DEBUG_CHILD
     argv = sync_pipe_add_arg(argv, &argc, "-Z");
-    argv = sync_pipe_add_arg(argv, &argc, "1");
 #endif
 
     return sync_pipe_run_command(argv, msg);
@@ -845,7 +843,6 @@ sync_linktype_list_open(gchar *ifname, gchar **msg) {
     /* dumpcap should be running in capture child mode (hidden feature) */
 #ifndef DEBUG_CHILD
     argv = sync_pipe_add_arg(argv, &argc, "-Z");
-    argv = sync_pipe_add_arg(argv, &argc, "1");
 #endif
 
     return sync_pipe_run_command(argv, msg);
@@ -883,7 +880,6 @@ sync_interface_stats_open(int *read_fd, int *fork_child, gchar **msg) {
     /* dumpcap should be running in capture child mode (hidden feature) */
 #ifndef DEBUG_CHILD
     argv = sync_pipe_add_arg(argv, &argc, "-Z");
-    argv = sync_pipe_add_arg(argv, &argc, "1");
 #endif
 
     return sync_pipe_open_command(argv, read_fd, fork_child, msg);
index 7047a6297a1029a8d448039c38535b9f3d677f79..41603be2e1014a68f7b9e09a7028d6dd476f96ab 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -85,8 +85,6 @@ void exit_main(int err) __attribute__ ((noreturn));
 void exit_main(int err);
 #endif
 
-/* Sync pipe file descriptor. */
-static int sync_pipe_fd;
 
 static void
 print_usage(gboolean print_ver) {
@@ -255,7 +253,7 @@ main(int argc, char *argv[])
   gboolean             print_statistics = FALSE;
   int                  status, run_once_args = 0;
 
-#define OPTSTRING_INIT "a:b:c:Df:hi:LMpSs:vw:y:Z:"
+#define OPTSTRING_INIT "a:b:c:Df:hi:LMpSs:vw:y:Z"
 
 #ifdef _WIN32
 #define OPTSTRING_WIN32 "B:"
@@ -364,10 +362,9 @@ main(int argc, char *argv[])
       /*** hidden option: Wireshark child mode (using binary output messages) ***/
       case 'Z':
           capture_child = TRUE;
-          sync_pipe_fd = get_positive_int(optarg, "sync pipe file descriptor");
 #ifdef _WIN32
           /* set output pipe to binary mode, to avoid ugly text conversions */
-         _setmode(sync_pipe_fd, O_BINARY);
+         _setmode(2, O_BINARY);
 #endif
           break;
 
@@ -557,7 +554,7 @@ report_packet_count(int packet_count)
     if(capture_child) {
         g_snprintf(tmp, sizeof(tmp), "%d", packet_count);
         g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Packets: %s", tmp);
-        pipe_write_block(sync_pipe_fd, SP_PACKET_COUNT, tmp);
+        pipe_write_block(2, SP_PACKET_COUNT, tmp);
     } else {
         count += packet_count;
         fprintf(stderr, "\rPackets: %u ", count);
@@ -571,7 +568,7 @@ report_new_capture_file(const char *filename)
 {
     if(capture_child) {
         g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "File: %s", filename);
-        pipe_write_block(sync_pipe_fd, SP_FILE, filename);
+        pipe_write_block(2, SP_FILE, filename);
     } else {
         fprintf(stderr, "File: %s\n", filename);
         /* stderr could be line buffered */
@@ -584,7 +581,7 @@ report_cfilter_error(const char *cfilter, const char *errmsg)
 {
     if (capture_child) {
         g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Capture filter error: %s", errmsg);
-        pipe_write_block(sync_pipe_fd, SP_BAD_FILTER, errmsg);
+        pipe_write_block(2, SP_BAD_FILTER, errmsg);
     } else {
         fprintf(stderr,
           "Invalid capture filter: \"%s\"!\n"
@@ -603,7 +600,7 @@ report_capture_error(const char *error_msg, const char *secondary_error_msg)
             "Primary Error: %s", error_msg);
         g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
             "Secondary Error: %s", secondary_error_msg);
-       sync_pipe_errmsg_to_parent(sync_pipe_fd, error_msg, secondary_error_msg);
+       sync_pipe_errmsg_to_parent(2, error_msg, secondary_error_msg);
     } else {
         fprintf(stderr, "%s\n%s\n", error_msg, secondary_error_msg);
     }
@@ -618,7 +615,7 @@ report_packet_drops(int drops)
 
     if(capture_child) {
         g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Packets dropped: %s", tmp);
-        pipe_write_block(sync_pipe_fd, SP_DROPS, tmp);
+        pipe_write_block(2, SP_DROPS, tmp);
     } else {
         fprintf(stderr, "Packets dropped: %s\n", tmp);
         /* stderr could be line buffered */