]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: FIFO: temporarily keep a conv_handle in syscalls.cc:open
authorKen Brown <kbrown@cornell.edu>
Tue, 9 Feb 2021 17:11:02 +0000 (12:11 -0500)
committerKen Brown <kbrown@cornell.edu>
Fri, 19 Feb 2021 18:43:33 +0000 (13:43 -0500)
When a FIFO is opened, syscalls.cc:open always calls fstat on the
newly-created fhandler_fifo.  This results from a call to
device_access_denied.

To speed-up this fstat call, and therefore the open(2) call, use
PC_KEEP_HANDLE when the fhandler is created.  The resulting
conv_handle is retained until after the fstat call if the fhandler is
a FIFO; otherwise, it is closed immediately.

winsup/cygwin/syscalls.cc

index 32a155a1c917ad5a90361c8690ac92d3dea5a070..460fe6801303992cbb043635e44b768c7bdc9e2d 100644 (file)
@@ -1487,8 +1487,15 @@ open (const char *unix_path, int flags, ...)
          opt |= PC_CTTY;
        }
 
+      /* If we're opening a FIFO, we will call device_access_denied
+        below.  This leads to a call to fstat, which can use the
+        path_conv handle. */
+      opt |= PC_KEEP_HANDLE;
       if (!(fh = build_fh_name (unix_path, opt, stat_suffixes)))
        __leave;                /* errno already set */
+      opt &= ~PC_KEEP_HANDLE;
+      if (!fh->isfifo ())
+       fh->pc.close_conv_handle ();
       if ((flags & O_NOFOLLOW) && fh->issymlink () && !(flags & O_PATH))
        {
          set_errno (ELOOP);
@@ -1555,9 +1562,18 @@ open (const char *unix_path, int flags, ...)
          delete fh;
          fh = fh_file;
        }
-      else if ((fh->is_fs_special () && fh->device_access_denied (flags))
-              || !fh->open_with_arch (flags, mode & 07777))
-       __leave;                /* errno already set */
+      else
+       {
+         if (fh->is_fs_special ())
+           {
+             if (fh->device_access_denied (flags))
+               __leave;        /* errno already set */
+             else if (fh->isfifo ())
+               fh->pc.close_conv_handle ();
+           }
+         if (!fh->open_with_arch (flags, mode & 07777))
+           __leave;            /* errno already set */
+       }
       /* Move O_TMPFILEs to the bin to avoid blocking the parent dir. */
       if ((flags & O_TMPFILE) && !fh->pc.isremote ())
        try_to_bin (fh->pc, fh->get_handle (), DELETE,
This page took 0.035669 seconds and 5 git commands to generate.