This is the mail archive of the cygwin-cvs@cygwin.com 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]

[newlib-cygwin] Cygwin: AF_UNIX: fix dup


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4f1ee1a3e787009bbf1b13e163e92a7616418a04

commit 4f1ee1a3e787009bbf1b13e163e92a7616418a04
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sat Mar 10 21:12:27 2018 +0100

    Cygwin: AF_UNIX: fix dup
    
    Reorder so fhandler_socket::dup is called first.  Add missing
    duplication of backing_file_handle.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler_socket_unix.cc | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index 6e7d6f1..4f7d9e0 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -1029,7 +1029,21 @@ fhandler_socket_unix::~fhandler_socket_unix ()
 int
 fhandler_socket_unix::dup (fhandler_base *child, int flags)
 {
+  if (fhandler_socket::dup (child, flags))
+    {
+      __seterrno ();
+      return -1;
+    }
   fhandler_socket_unix *fhs = (fhandler_socket_unix *) child;
+  if (backing_file_handle && backing_file_handle != INVALID_HANDLE_VALUE
+      && !DuplicateHandle (GetCurrentProcess (), backing_file_handle,
+			    GetCurrentProcess (), &fhs->backing_file_handle,
+			    0, TRUE, DUPLICATE_SAME_ACCESS))
+    {
+      __seterrno ();
+      fhs->close ();
+      return -1;
+    }
   fhs->set_sun_path (get_sun_path ());
   fhs->set_peer_sun_path (get_peer_sun_path ());
   InitializeSRWLock (&fhs->conn_lock);
@@ -1038,7 +1052,7 @@ fhandler_socket_unix::dup (fhandler_base *child, int flags)
   fhs->connect_wait_thr = NULL;
   fhs->cwt_termination_evt = NULL;
   fhs->cwt_param = NULL;
-  return fhandler_socket::dup (child, flags);
+  return 0;
 }
 
 /* Waiter thread method.  Here we wait for a pipe instance to become


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