]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: FIFO: dup/fork/exec: make sure child starts unlocked
authorKen Brown <kbrown@cornell.edu>
Mon, 4 May 2020 15:36:20 +0000 (11:36 -0400)
committerKen Brown <kbrown@cornell.edu>
Fri, 8 May 2020 10:32:00 +0000 (06:32 -0400)
There can be deadlocks if the child starts with its fifo_client_lock
in the locked state.

winsup/cygwin/fhandler_fifo.cc

index f61e2fe72b35b8a82dd5cb168c55c4fa851b802e..4904a535d526f7fbddff7d74b432f9641fe29f23 100644 (file)
@@ -981,6 +981,9 @@ fhandler_fifo::dup (fhandler_base *child, int flags)
     }
   if (reader)
     {
+      /* Make sure the child starts unlocked. */
+      fhf->fifo_client_unlock ();
+
       fifo_client_lock ();
       for (i = 0; i < nhandlers; i++)
        {
@@ -1025,20 +1028,32 @@ fhandler_fifo::fixup_after_fork (HANDLE parent)
   fhandler_base::fixup_after_fork (parent);
   fork_fixup (parent, read_ready, "read_ready");
   fork_fixup (parent, write_ready, "write_ready");
-  fifo_client_lock ();
-  for (int i = 0; i < nhandlers; i++)
-  fork_fixup (parent, fc_handler[i].h, "fc_handler[].h");
-  fifo_client_unlock ();
-  if (reader && !listen_client ())
-    debug_printf ("failed to start lct, %E");
+  if (reader)
+    {
+      /* Make sure the child starts unlocked. */
+      fifo_client_unlock ();
+
+      fifo_client_lock ();
+      for (int i = 0; i < nhandlers; i++)
+       fork_fixup (parent, fc_handler[i].h, "fc_handler[].h");
+      fifo_client_unlock ();
+      if (!listen_client ())
+       debug_printf ("failed to start lct, %E");
+    }
 }
 
 void
 fhandler_fifo::fixup_after_exec ()
 {
   fhandler_base::fixup_after_exec ();
-  if (reader && !listen_client ())
-    debug_printf ("failed to start lct, %E");
+  if (reader && !close_on_exec ())
+    {
+      /* Make sure the child starts unlocked. */
+      fifo_client_unlock ();
+
+      if (!listen_client ())
+       debug_printf ("failed to start lct, %E");
+    }
 }
 
 void
This page took 0.031343 seconds and 5 git commands to generate.