Report the appropriate secondary message for ENOSPC and EDQUOT.
authorGuy Harris <guy@alum.mit.edu>
Sat, 12 May 2018 20:42:38 +0000 (13:42 -0700)
committerGuy Harris <guy@alum.mit.edu>
Sat, 12 May 2018 22:06:14 +0000 (22:06 +0000)
Don't tell the user that, if they run out of space or go over their disk
quote, they should report that as a Wireshark bug; instead, tell them
that they're going to need to free up some space or do the capture to a
different file system.

Clean up some argument types, and get rid of tabs in indentation, while
we're at it.

Change-Id: I7839f38c14253a114e7e02e762243df5e09682ef
Ping-Bug: 14677
Reviewed-on: https://code.wireshark.org/review/27472
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
dumpcap.c

index 845c27114ec4d4a3238b0ca4ba6ceb8cbe7c2ee8..5d922d138506b067a11448c7c504f485229a7fe3 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -384,8 +384,11 @@ static void capture_loop_queue_packet_cb(u_char *pcap_src_p, const struct pcap_p
                                          const u_char *pd);
 static void capture_loop_write_pcapng_cb(capture_src *pcap_src, const struct pcapng_block_header_s *bh, const u_char *pd);
 static void capture_loop_queue_pcapng_cb(capture_src *pcap_src, const struct pcapng_block_header_s *bh, const u_char *pd);
-static void capture_loop_get_errmsg(char *errmsg, int errmsglen, const char *fname,
-                                    int err, gboolean is_close);
+static void capture_loop_get_errmsg(char *errmsg, size_t errmsglen,
+                                    char *secondary_errmsg,
+                                    size_t secondary_errmsglen,
+                                    const char *fname, int err,
+                                    gboolean is_close);
 
 static void WS_NORETURN exit_main(int err);
 
@@ -2743,8 +2746,8 @@ static void capture_loop_close_input(loop_data *ld)
                 g_list_free_full(pcap_src->cap_pipe_info.pcapng.saved_blocks, g_free);
                 pcap_src->cap_pipe_info.pcapng.saved_blocks = NULL;
             }
-       } else {
-           /* Capture device.  If open, close the pcap_t. */
+        } else {
+            /* Capture device.  If open, close the pcap_t. */
             if (pcap_src->pcap_h != NULL) {
                 g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_close_input: closing %p", (void *)pcap_src->pcap_h);
                 pcap_close(pcap_src->pcap_h);
@@ -3857,9 +3860,10 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
     if (global_ld.err == 0) {
         write_ok = TRUE;
     } else {
-        capture_loop_get_errmsg(errmsg, sizeof(errmsg), capture_opts->save_file,
-                                global_ld.err, FALSE);
-        report_capture_error(errmsg, please_report);
+        capture_loop_get_errmsg(errmsg, sizeof(errmsg), secondary_errmsg,
+                                sizeof(secondary_errmsg),
+                                capture_opts->save_file, global_ld.err, FALSE);
+        report_capture_error(errmsg, secondary_errmsg);
         write_ok = FALSE;
     }
 
@@ -3880,9 +3884,10 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
     /* If we've displayed a message about a write error, there's no point
        in displaying another message about an error on close. */
     if (!close_ok && write_ok) {
-        capture_loop_get_errmsg(errmsg, sizeof(errmsg), capture_opts->save_file, err_close,
-                                TRUE);
-        report_capture_error(errmsg, "");
+        capture_loop_get_errmsg(errmsg, sizeof(errmsg), secondary_errmsg,
+                                sizeof(secondary_errmsg),
+                                capture_opts->save_file, err_close, TRUE);
+        report_capture_error(errmsg, secondary_errmsg);
     }
 
     /*
@@ -3985,45 +3990,56 @@ capture_loop_stop(void)
 
 
 static void
-capture_loop_get_errmsg(char *errmsg, int errmsglen, const char *fname,
+capture_loop_get_errmsg(char *errmsg, size_t errmsglen, char *secondary_errmsg,
+                        size_t secondary_errmsglen, const char *fname,
                         int err, gboolean is_close)
 {
+    static const char find_space[] =
+        "You will need to free up space on that file system"
+        " or put the capture file on a different file system.";
+
     switch (err) {
 
     case ENOSPC:
-        g_snprintf(errmsg, errmsglen,
+        g_snprintf(errmsg, (gulong)errmsglen,
                    "Not all the packets could be written to the file"
                    " to which the capture was being saved\n"
                    "(\"%s\") because there is no space left on the file system\n"
                    "on which that file resides.",
                    fname);
+        g_snprintf(secondary_errmsg, (gulong)secondary_errmsglen, "%s",
+                   find_space);
         break;
 
 #ifdef EDQUOT
     case EDQUOT:
-        g_snprintf(errmsg, errmsglen,
+        g_snprintf(errmsg, (gulong)errmsglen,
                    "Not all the packets could be written to the file"
                    " to which the capture was being saved\n"
                    "(\"%s\") because you are too close to, or over,"
                    " your disk quota\n"
                    "on the file system on which that file resides.",
                    fname);
+        g_snprintf(secondary_errmsg, (gulong)secondary_errmsglen, "%s",
+                   find_space);
         break;
 #endif
 
     default:
         if (is_close) {
-            g_snprintf(errmsg, errmsglen,
+            g_snprintf(errmsg, (gulong)errmsglen,
                        "The file to which the capture was being saved\n"
                        "(\"%s\") could not be closed: %s.",
                        fname, g_strerror(err));
         } else {
-            g_snprintf(errmsg, errmsglen,
+            g_snprintf(errmsg, (gulong)errmsglen,
                        "An error occurred while writing to the file"
                        " to which the capture was being saved\n"
                        "(\"%s\"): %s.",
                        fname, g_strerror(err));
         }
+        g_snprintf(secondary_errmsg, (gulong)secondary_errmsglen,
+                   "%s", please_report);
         break;
     }
 }