diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index 0119581df..7080144b9 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -421,14 +421,6 @@ frok::parent (volatile char * volatile stack_here) this_errno = EAGAIN; #ifdef DEBUGGING0 error ("child remember failed"); -#endif - goto cleanup; - } - if (!child.reattach ()) - { - this_errno = EAGAIN; -#ifdef DEBUGGING0 - error ("child reattach failed"); #endif goto cleanup; } @@ -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);