TShark doesn't need wtap_fdreopen(), as it doesn't do saves and thus
authorGuy Harris <guy@alum.mit.edu>
Fri, 1 Jun 2012 16:55:10 +0000 (16:55 -0000)
committerGuy Harris <guy@alum.mit.edu>
Fri, 1 Jun 2012 16:55:10 +0000 (16:55 -0000)
doesn't do safe saves, so wtap_fdreopen() always needs to reopen the
random file descriptor.

At the point where a safe save is done, the sequential read is done, so
the sequential stream is closed; there's no need to reopen it.

(The former fourth argument to wtap_fdreopen() wasn't an indication of
whether the file was compressed, it was an indicationof whether the
random stream should be reopened.)

svn path=/trunk/; revision=42977

file.c
wiretap/file_access.c
wiretap/wtap.h

diff --git a/file.c b/file.c
index 854d52ec69dd1903ac8a64b7a8f1432f31aece88..5248ba3fda2ad16cb3b83442a2d5ba353a9c15f1 100644 (file)
--- a/file.c
+++ b/file.c
@@ -3983,8 +3983,9 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                     file_rename_error_message(errno), fname);
 #ifdef _WIN32
-      /* Attempt to reopen the file descriptors using fname. */
-      if (!wtap_fdreopen(cf->wth, fname, &err, compressed)) {
+      /* Attempt to reopen the random file descriptor using fname.
+         (At this point, the sequential file descriptor is closed.) */
+      if (!wtap_fdreopen(cf->wth, fname, &err)) {
         /* Oh, well, we're screwed. */
         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                       file_open_error_message(err, FALSE), fname);
index 30e9d6164f2cc2e3b72b0f74d09fb8a9b2731388..34dfaff03825fbcfc0d3fd3ef6c1326332922620 100644 (file)
@@ -411,47 +411,40 @@ success:
  * stream and, if do_random is TRUE, to the random stream.  Used on Windows
  * after the rename of a file we had open was done or if the rename of a
  * file on top of a file we had open failed.
+ *
+ * This is only required by Wireshark, not TShark, and, at the point that
+ * Wireshark is doing this, the sequential stream is closed, and the
+ * random stream is open, so this refuses to open pipes, and only
+ * reopens the random stream.
  */
 gboolean
-wtap_fdreopen(wtap *wth, const char *filename, int *err, gboolean do_random)
+wtap_fdreopen(wtap *wth, const char *filename, int *err)
 {
-       int     fd;
        ws_statb64 statb;
-       gboolean use_stdin = FALSE;
 
-       /* open standard input if filename is '-' */
-       if (strcmp(filename, "-") == 0)
-               use_stdin = TRUE;
+       /*
+        * We need two independent descriptors for random access, so
+        * they have different file positions.  If we're opening the
+        * standard input, we can only dup it to get additional
+        * descriptors, so we can't have two independent descriptors,
+        * and thus can't do random access.
+        */
+       if (strcmp(filename, "-") == 0) {
+               *err = WTAP_ERR_RANDOM_OPEN_STDIN;
+               return FALSE;
+       }
 
        /* First, make sure the file is valid */
-       if (use_stdin) {
-               if (ws_fstat64(0, &statb) < 0) {
-                       *err = errno;
-                       return FALSE;
-               }
-       } else {
-               if (ws_stat64(filename, &statb) < 0) {
-                       *err = errno;
-                       return FALSE;
-               }
+       if (ws_stat64(filename, &statb) < 0) {
+               *err = errno;
+               return FALSE;
        }
        if (S_ISFIFO(statb.st_mode)) {
                /*
-                * Opens of FIFOs are allowed only when not opening
-                * for random access.
-                *
-                * XXX - currently, we do seeking when trying to find
-                * out the file type, so we don't actually support
-                * opening FIFOs.  However, we may eventually
-                * do buffering that allows us to do at least some
-                * file type determination even on pipes, so we
-                * allow FIFO opens and let things fail later when
-                * we try to seek.
+                * Opens of FIFOs are not allowed; see above.
                 */
-               if (do_random) {
-                       *err = WTAP_ERR_RANDOM_OPEN_PIPE;
-                       return FALSE;
-               }
+               *err = WTAP_ERR_RANDOM_OPEN_PIPE;
+               return FALSE;
        } else if (S_ISDIR(statb.st_mode)) {
                /*
                 * Return different errors for "this is a directory"
@@ -465,56 +458,11 @@ wtap_fdreopen(wtap *wth, const char *filename, int *err, gboolean do_random)
                return FALSE;
        }
 
-       /*
-        * We need two independent descriptors for random access, so
-        * they have different file positions.  If we're opening the
-        * standard input, we can only dup it to get additional
-        * descriptors, so we can't have two independent descriptors,
-        * and thus can't do random access.
-        */
-       if (use_stdin && do_random) {
-               *err = WTAP_ERR_RANDOM_OPEN_STDIN;
-               return FALSE;
-       }
-
        /* Open the file */
        errno = WTAP_ERR_CANT_OPEN;
-       if (use_stdin) {
-               /*
-                * We dup FD 0, so that we don't have to worry about
-                * a file_close of wth->fh closing the standard
-                * input of the process.
-                */
-               fd = ws_dup(0);
-               if (fd < 0) {
-                       *err = errno;
-                       return FALSE;
-               }
-#ifdef _WIN32
-               if (_setmode(fd, O_BINARY) == -1) {
-                       /* "Shouldn't happen" */
-                       *err = errno;
-                       return FALSE;
-               }
-#endif
-               if (!(wth->fh = file_fdopen(fd))) {
-                       *err = errno;
-                       ws_close(fd);
-                       return FALSE;
-               }
-       } else {
-               if (!file_fdreopen(wth->fh, filename)) {
-                       *err = errno;
-                       return FALSE;
-               }
-       }
-
-       if (do_random) {
-               if (!file_fdreopen(wth->random_fh, filename)) {
-                       *err = errno;
-                       file_fdclose(wth->fh);
-                       return FALSE;
-               }
+       if (!file_fdreopen(wth->random_fh, filename)) {
+               *err = errno;
+               return FALSE;
        }
        return TRUE;
 }
index 69a5858745fa9cc2b75e28af457334244f9e6188..717d018a7120b2da0421b41d0f70a72db102f1ce 100644 (file)
@@ -1086,9 +1086,8 @@ void wtap_write_shb_comment(wtap *wth, gchar *comment);
 /*** close the file descriptors for the current file ***/
 void wtap_fdclose(wtap *wth);
 
-/*** reopen the file descriptors for the current file ***/
-gboolean wtap_fdreopen(wtap *wth, const char *filename, int *err,
-       gboolean do_random);
+/*** reopen the random file descriptor for the current file ***/
+gboolean wtap_fdreopen(wtap *wth, const char *filename, int *err);
 
 /*** close the current file ***/
 void wtap_sequential_close(wtap *wth);