Add a note about the IrDA dissector crash.
[metze/wireshark/wip.git] / capture.c
index 4e21495edf4815a9038379896b35127fdcc6dd4e..12f9cbe3f3e4b44a87a51a906ec0961be20ccbf5 100644 (file)
--- a/capture.c
+++ b/capture.c
 
 #ifdef HAVE_LIBPCAP
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
@@ -65,6 +69,7 @@
 #include "capture-wpcap.h"
 #endif
 #include "ui_util.h"
+#include "log.h"
 
 
 
@@ -82,13 +87,27 @@ capture_start(capture_options *capture_opts)
   /* close the currently loaded capture file */
   cf_close(capture_opts->cf);
 
+  g_assert(capture_opts->state == CAPTURE_STOPPED);
+  capture_opts->state = CAPTURE_PREPARING;
+
+  g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ...");
+
   /* try to start the capture child process */
-  ret = sync_pipe_start(capture_opts, capture_opts->save_file == NULL);
+  ret = sync_pipe_start(capture_opts);
   if(!ret) {
       if(capture_opts->save_file != NULL) {
           g_free(capture_opts->save_file);
           capture_opts->save_file = NULL;
       }
+
+      capture_opts->state = CAPTURE_STOPPED;
+  } else {
+      /* the capture child might not respond shortly after bringing it up */
+      /* (especially it will block, if no input coming from an input capture pipe (e.g. mkfifo) is coming in) */
+
+      /* to prevent problems, bring the main GUI into "capture mode" right after successfully */
+      /* spawn/exec the capture child, without waiting for any response from it */
+      cf_callback_invoke(cf_cb_live_capture_prepared, capture_opts);
   }
 
   return ret;
@@ -98,6 +117,8 @@ capture_start(capture_options *capture_opts)
 void
 capture_stop(capture_options *capture_opts)
 {
+  g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Stop ...");
+
   /* stop the capture child gracefully */
   sync_pipe_stop(capture_opts);
 }
@@ -106,6 +127,8 @@ capture_stop(capture_options *capture_opts)
 void
 capture_restart(capture_options *capture_opts)
 {
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Restart");
+
     capture_opts->restart = TRUE;
     capture_stop(capture_opts);
 }
@@ -114,6 +137,8 @@ capture_restart(capture_options *capture_opts)
 void
 capture_kill_child(capture_options *capture_opts)
 {
+  g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_INFO, "Capture Kill");
+
   /* kill the capture child */
   sync_pipe_kill(capture_opts);
 }
@@ -209,7 +234,12 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
   int  err;
 
 
-  /*g_warning("New capture file: %s", new_file);*/
+  if(capture_opts->state == CAPTURE_PREPARING) {
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started!");
+  }
+  g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "File: \"%s\"", new_file);
+
+  g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
 
   /* free the old filename */
   if(capture_opts->save_file != NULL) {
@@ -251,6 +281,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
     cf_callback_invoke(cf_cb_live_capture_fixed_started, capture_opts);
   }
 
+  capture_opts->state = CAPTURE_RUNNING;
 
   return TRUE;
 }
@@ -278,6 +309,7 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
          file.
 
          XXX - abort on a read error? */
+         cf_callback_invoke(cf_cb_live_capture_update_continue, capture_opts->cf);
          main_window_update();
       break;
 
@@ -298,8 +330,11 @@ capture_input_closed(capture_options *capture_opts)
     int  err;
 
 
-    /* if we have no file (happens if an error occured), do a fake start */
-    if(capture_opts->save_file == NULL) {
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture stopped!");
+    g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
+
+    /* if we didn't started the capture (happens if an error occured), do a fake start */
+    if(capture_opts->state == CAPTURE_PREPARING) {
         if(capture_opts->real_time_mode) {
             cf_callback_invoke(cf_cb_live_capture_update_started, capture_opts);
         } else {
@@ -308,10 +343,7 @@ capture_input_closed(capture_options *capture_opts)
     }
 
     if(capture_opts->real_time_mode) {
-        /* first of all, update the file length field */
-        cf_update_f_len(capture_opts->cf);
-
-        /* we are not doing a capture any more */
+        /* first of all, we are not doing a capture any more */
         cf_callback_invoke(cf_cb_live_capture_update_finished, capture_opts->cf);
 
         /* Read what remains of the capture file, and finish the capture.
@@ -351,6 +383,8 @@ capture_input_closed(capture_options *capture_opts)
         }
     }
 
+    capture_opts->state = CAPTURE_STOPPED;
+
     /* if we couldn't open a capture file, there's nothing more for us to do */
     if(capture_opts->save_file == NULL) {
         cf_close(capture_opts->cf);