[newlib-cygwin] Cygwin: FIFO: update clone and dup

Corinna Vinschen corinna@sourceware.org
Wed Mar 27 13:03:00 GMT 2019


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

commit 035bf7dc84d98f6f643ba2dd00b08c34dc8eb984
Author: Ken Brown <kbrown@cornell.edu>
Date:   Fri Mar 22 19:30:39 2019 +0000

    Cygwin: FIFO: update clone and dup
    
    Deal with all clients.

Diff:
---
 winsup/cygwin/fhandler.h       |  8 +++++---
 winsup/cygwin/fhandler_fifo.cc | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index af5f500..0ebc44e 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1309,9 +1309,11 @@ public:
   fhandler_fifo *clone (cygheap_types malloc_type = HEAP_FHANDLER)
   {
     void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_fifo));
-    fhandler_fifo *fh = new (ptr) fhandler_fifo (ptr);
-    copyto (fh);
-    return fh;
+    fhandler_fifo *fhf = new (ptr) fhandler_fifo (ptr);
+    copyto (fhf);
+    for (int i = 0; i < nclients; i++)
+      fhf->client[i].fh = client[i].fh->fhandler_base::clone ();
+    return fhf;
   }
 };
 
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 1dcb3b3..c295c23 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -816,6 +816,31 @@ fhandler_fifo::dup (fhandler_base *child, int flags)
       __seterrno ();
       return -1;
     }
+  for (int i = 0; i < nclients; i++)
+    {
+      if (!DuplicateHandle (GetCurrentProcess (), client[i].fh->get_handle (),
+			    GetCurrentProcess (),
+			    &fhf->client[i].fh->get_handle (),
+			    0, true, DUPLICATE_SAME_ACCESS)
+	  || !DuplicateHandle (GetCurrentProcess (), client[i].connect_evt,
+			       GetCurrentProcess (),
+			       &fhf->client[i].connect_evt,
+			       0, true, DUPLICATE_SAME_ACCESS)
+	  || !DuplicateHandle (GetCurrentProcess (), client[i].dummy_evt,
+			       GetCurrentProcess (),
+			       &fhf->client[i].dummy_evt,
+			       0, true, DUPLICATE_SAME_ACCESS))
+	{
+	  CloseHandle (fhf->read_ready);
+	  CloseHandle (fhf->write_ready);
+	  fhf->close ();
+	  __seterrno ();
+	  return -1;
+	}
+    }
+  fhf->listen_client_thr = NULL;
+  fhf->lct_termination_evt = NULL;
+  fhf->fifo_client_unlock ();
   return 0;
 }



More information about the Cygwin-cvs mailing list