public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: fork: attach child not before success
@ 2019-07-31 16:58 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2019-07-31 16:58 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 2986a524d853ab6d06bf88b65e0e9d60cea51dcc
Author: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
Date:   Wed Jul 31 12:35:33 2019 +0200

    Cygwin: fork: attach child not before success
    
    Do not attach to the child before it was successfully initialized, or we
    would need more sophisticated cleanup on child initialization failure,
    like suppressing SIGCHILD delivery with multiple threads ("waitproc")
    involved.
    
    Improves "Cygwin: fork: Remember child not before success.",
    commit f03ea8e1c57bd5cea83f6cd47fa02870bdfeb1c5, which leads to fork
    problems if cygserver is running:
    
    https://cygwin.com/ml/cygwin-patches/2019-q2/msg00155.html

Diff:
---
 winsup/cygwin/fork.cc | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 0119581..7080144 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -424,14 +424,6 @@ frok::parent (volatile char * volatile stack_here)
 #endif
       goto cleanup;
     }
-  if (!child.reattach ())
-    {
-      this_errno = EAGAIN;
-#ifdef DEBUGGING0
-      error ("child reattach failed");
-#endif
-      goto cleanup;
-    }
 
   /* CHILD IS STOPPED */
   debug_printf ("child is alive (but stopped)");
@@ -516,6 +508,17 @@ frok::parent (volatile char * volatile stack_here)
 	}
     }
 
+  /* Do not attach to the child before it has successfully initialized.
+     Otherwise we may wait forever, or deliver an orphan SIGCHILD. */
+  if (!child.reattach ())
+    {
+      this_errno = EAGAIN;
+#ifdef DEBUGGING0
+      error ("child reattach failed");
+#endif
+      goto cleanup;
+    }
+
   /* Finally start the child up. */
   resume_child (forker_finished);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-31 16:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31 16:58 [newlib-cygwin] Cygwin: fork: attach child not before success Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).