Fix Bug #5716: "dumpcap: -q option behavior doesn't match documentation"
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 24 Feb 2011 19:26:38 +0000 (19:26 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 24 Feb 2011 19:26:38 +0000 (19:26 +0000)
Rework code slightly to print "Packets captured: " at 'dumpcap -q ...' exit.
Also: SigInfo now prints: "Packets captured:  n" iso "n Packets captured".

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

dumpcap.c

index 9b3ee11c1dae6b38bafe4fe024798967bab14292..2ab7e70adf0015171cf3a6dfbadfa4c2f2d49d77 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -173,7 +173,7 @@ static void capture_loop_stop(void);
  * blocked in the select() when the signal arrives, and can just bail
  * out of the loop at that point.
  *
- * However, we don't want to that on BSD (because "select()" doesn't work
+ * However, we don't want to do that on BSD (because "select()" doesn't work
  * correctly on BPF devices on at least some releases of some flavors of
  * BSD), and we don't want to do it on Windows (because "select()" is
  * something for sockets, not for arbitrary handles).  (Note that "Windows"
@@ -317,7 +317,7 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
 
 /* capture related options */
 static capture_options global_capture_opts;
-static gboolean quiet;
+static gboolean quiet = FALSE;
 
 static void capture_loop_packet_cb(u_char *user, const struct pcap_pkthdr *phdr,
   const u_char *pd);
@@ -1354,19 +1354,27 @@ capture_cleanup_handler(int signum _U_)
 #endif
 
 
-#ifdef SIGINFO
 static void
-report_counts(void)
+report_capture_count(void)
 {
   /* Don't print this if we're a capture child. */
   if (!capture_child) {
     if (quiet) {
       /* Report the count only if we aren't printing a packet count
          as packets arrive. */
-      fprintf(stderr, "%u packet%s captured\n", global_ld.packet_count,
-              plurality(global_ld.packet_count, "", "s"));
+        fprintf(stderr, "Packets captured: %u\n", global_ld.packet_count);
+      /* stderr could be line buffered */
+      fflush(stderr);
     }
   }
+}
+
+
+#ifdef SIGINFO
+static void
+report_counts_for_siginfo(void)
+{
+  report_capture_count();
   infoprint = FALSE; /* we just reported it */
 }
 
@@ -1381,7 +1389,7 @@ report_counts_siginfo(int signum _U_)
   if (infodelay)
     infoprint = TRUE;
   else
-    report_counts();
+    report_counts_for_siginfo();
   errno = sav_errno;
 }
 #endif /* SIGINFO */
@@ -3129,6 +3137,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
    * mode, cap_pipe_open_live() will say "End of file on pipe during open".
    */
 
+  report_capture_count();  /* print final capture count only if (quiet && !capture_child) */
+
   /* get packet drop statistics from pcap */
   if(global_ld.pcap_h != NULL) {
     g_assert(!global_ld.from_cap_pipe);
@@ -4024,7 +4034,7 @@ report_new_capture_file(const char *filename)
          * If a SIGINFO handler asked us to write out capture counts, do so.
          */
         if (infoprint)
-          report_counts();
+          report_counts_for_siginfo();
 #endif /* SIGINFO */
     }
 }