This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH 2/2] Cygwin: fork: Attach child not before success.
- From: Michael Haubenwallner <michael dot haubenwallner at ssi-schaefer dot com>
- To: cygwin-patches at cygwin dot com
- Cc: michael dot haubenwallner at ssi-schaefer dot com
- Date: Tue, 30 Jul 2019 17:22:56 +0200
- Subject: [PATCH 2/2] Cygwin: fork: Attach child not before success.
- References: <20190730152256.22873-1-michael.haubenwallner@ssi-schaefer.com>
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
---
winsup/cygwin/fork.cc | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 59b13806c..c6ba8cf65 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -416,11 +416,11 @@ frok::parent (volatile char * volatile stack_here)
it in afterwards. This requires more bookkeeping than I like, though,
so we'll just do it the easy way. So, terminate any child process if
we can't actually record the pid in the internal table. */
- if (!child.remember (false))
+ if (!child.remember_without_attach (false))
{
this_errno = EAGAIN;
#ifdef DEBUGGING0
- error ("child remember failed");
+ error ("child remember_without_attach failed");
#endif
goto cleanup;
}
@@ -508,6 +508,15 @@ frok::parent (volatile char * volatile stack_here)
}
}
+ if (!child.reattach ())
+ {
+ this_errno = EAGAIN;
+#ifdef DEBUGGING0
+ error ("child reattach failed");
+#endif
+ goto cleanup;
+ }
+
/* Finally start the child up. */
resume_child (forker_finished);
--
2.21.0