This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH draft 6/6] Cygwin: add fhandler_base::npfs_handle


This gets a handle to the Windows named pipe file system directory.

It replaces the three identical functions of the same name in the
classes fhandler_pipe, fhandler_fifo, and fhandler_socket_unix.
---
 winsup/cygwin/fhandler.cc             | 30 +++++++++++++++++++++++++
 winsup/cygwin/fhandler.h              |  7 +++---
 winsup/cygwin/fhandler_fifo.cc        | 30 -------------------------
 winsup/cygwin/fhandler_pipe.cc        | 32 +--------------------------
 winsup/cygwin/fhandler_socket_unix.cc | 30 -------------------------
 5 files changed, 35 insertions(+), 94 deletions(-)

diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index bb618fa88..7619db6c7 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1835,3 +1835,33 @@ fhandler_base::fpathconf (int v)
     }
   return -1;
 }
+
+NTSTATUS
+fhandler_base::npfs_handle (HANDLE &nph)
+{
+  static NO_COPY SRWLOCK npfs_lock;
+  static NO_COPY HANDLE npfs_dirh;
+
+  NTSTATUS status = STATUS_SUCCESS;
+  OBJECT_ATTRIBUTES attr;
+  IO_STATUS_BLOCK io;
+
+  /* Lockless after first call. */
+  if (npfs_dirh)
+    {
+      nph = npfs_dirh;
+      return STATUS_SUCCESS;
+    }
+  AcquireSRWLockExclusive (&npfs_lock);
+  if (!npfs_dirh)
+    {
+      InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
+      status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+			   &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
+			   0);
+    }
+  ReleaseSRWLockExclusive (&npfs_lock);
+  if (NT_SUCCESS (status))
+    nph = npfs_dirh;
+  return status;
+}
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 55b49bced..0aedb63c3 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -385,6 +385,10 @@ public:
   virtual int dup (fhandler_base *child, int flags);
   virtual int fpathconf (int);
 
+  /* Get a handle to the named pipe file system directory.  Used by
+     fhandler_pipe, fhandler_fifo, and fhandler_socket_unix. */
+  static NTSTATUS npfs_handle (HANDLE &);
+
   virtual HANDLE mmap (caddr_t *addr, size_t len, int prot,
 		       int flags, off_t off);
   virtual int munmap (HANDLE h, caddr_t addr, size_t len);
@@ -1008,7 +1012,6 @@ class fhandler_socket_unix : public fhandler_socket
   int send_sock_info (bool from_bind);
   int grab_admin_pkg ();
   int recv_peer_info ();
-  static NTSTATUS npfs_handle (HANDLE &nph);
   HANDLE create_pipe (bool single_instance);
   HANDLE create_pipe_instance ();
   NTSTATUS open_pipe (PUNICODE_STRING pipe_name, bool xchg_sock_info);
@@ -1143,7 +1146,6 @@ public:
   int __reg3 fadvise (off_t, off_t, int);
   int __reg3 ftruncate (off_t, bool);
   int init (HANDLE, DWORD, mode_t, int64_t);
-  static NTSTATUS npfs_handle (HANDLE &);
   static int create (fhandler_pipe *[2], unsigned, int);
   static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD,
 		       const char *, DWORD, int64_t *unique_id = NULL);
@@ -1198,7 +1200,6 @@ class fhandler_fifo: public fhandler_base
   bool reader, writer, duplexer;
   size_t max_atomic_write;
   bool __reg2 wait (HANDLE);
-  static NTSTATUS npfs_handle (HANDLE &);
   HANDLE create_pipe_instance (bool);
   NTSTATUS open_pipe (HANDLE&);
   int add_client_handler ();
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 3fabbc3b4..777ef0b24 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -118,36 +118,6 @@ set_pipe_non_blocking (HANDLE ph, bool nonblocking)
     debug_printf ("NtSetInformationFile(FilePipeInformation): %y", status);
 }
 
-NTSTATUS
-fhandler_fifo::npfs_handle (HANDLE &nph)
-{
-  static NO_COPY SRWLOCK npfs_lock;
-  static NO_COPY HANDLE npfs_dirh;
-
-  NTSTATUS status = STATUS_SUCCESS;
-  OBJECT_ATTRIBUTES attr;
-  IO_STATUS_BLOCK io;
-
-  /* Lockless after first call. */
-  if (npfs_dirh)
-    {
-      nph = npfs_dirh;
-      return STATUS_SUCCESS;
-    }
-  AcquireSRWLockExclusive (&npfs_lock);
-  if (!npfs_dirh)
-    {
-      InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
-      status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
-			   &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
-			   0);
-    }
-  ReleaseSRWLockExclusive (&npfs_lock);
-  if (NT_SUCCESS (status))
-    nph = npfs_dirh;
-  return status;
-}
-
 /* Called when a FIFO is first opened for reading and again each time
    a new client handler is needed.  Each pipe instance is created in
    blocking mode so that we can easily wait for a connection.  After
diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc
index d56ea4c88..4464ec005 100644
--- a/winsup/cygwin/fhandler_pipe.cc
+++ b/winsup/cygwin/fhandler_pipe.cc
@@ -583,36 +583,6 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode)
   return res;
 }
 
-NTSTATUS
-fhandler_pipe::npfs_handle (HANDLE &nph)
-{
-  static NO_COPY SRWLOCK npfs_lock;
-  static NO_COPY HANDLE npfs_dirh;
-
-  NTSTATUS status = STATUS_SUCCESS;
-  OBJECT_ATTRIBUTES attr;
-  IO_STATUS_BLOCK io;
-
-  /* Lockless after first call. */
-  if (npfs_dirh)
-    {
-      nph = npfs_dirh;
-      return STATUS_SUCCESS;
-    }
-  AcquireSRWLockExclusive (&npfs_lock);
-  if (!npfs_dirh)
-    {
-      InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
-      status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
-			   &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
-			   0);
-    }
-  ReleaseSRWLockExclusive (&npfs_lock);
-  if (NT_SUCCESS (status))
-    nph = npfs_dirh;
-  return status;
-}
-
 static int
 nt_create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
 		DWORD psize, int64_t *unique_id)
@@ -630,7 +600,7 @@ nt_create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
   if (w)
     *w = NULL;
 
-  status = fhandler_pipe::npfs_handle (npfsh);
+  status = fhandler_base::npfs_handle (npfsh);
   if (!NT_SUCCESS (status))
     {
       __seterrno_from_nt_status (status);
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index eea7e76b3..23d3f403f 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -804,36 +804,6 @@ fhandler_socket_unix::recv_peer_info ()
   return ret;
 }
 
-NTSTATUS
-fhandler_socket_unix::npfs_handle (HANDLE &nph)
-{
-  static NO_COPY SRWLOCK npfs_lock;
-  static NO_COPY HANDLE npfs_dirh;
-
-  NTSTATUS status = STATUS_SUCCESS;
-  OBJECT_ATTRIBUTES attr;
-  IO_STATUS_BLOCK io;
-
-  /* Lockless after first call. */
-  if (npfs_dirh)
-    {
-      nph = npfs_dirh;
-      return STATUS_SUCCESS;
-    }
-  AcquireSRWLockExclusive (&npfs_lock);
-  if (!npfs_dirh)
-    {
-      InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
-      status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
-			   &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
-			   0);
-    }
-  ReleaseSRWLockExclusive (&npfs_lock);
-  if (NT_SUCCESS (status))
-    nph = npfs_dirh;
-  return status;
-}
-
 HANDLE
 fhandler_socket_unix::create_pipe (bool single_instance)
 {
-- 
2.17.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]