During fork, the child process requires the process table to be
initialized for fixup_shms_after_fork, while still allowing subsequent
dlls.load_after_fork to fail silently (for when the "forkable" hardlinks
are not created yet).

Prepares to improve "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/pinfo.h    | 9 ++++++++-
 winsup/cygwin/sigproc.cc | 4 +---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index 8cf1bba2e..35f6f5ac6 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -195,13 +195,20 @@ public:
     destroy = res ? false : true;
     return res;
   }
-  int remember (bool detach)
+  int remember_without_attach (bool detach)
   {
     int res = proc_subproc (detach ? PROC_DETACHED_CHILD : PROC_ADDCHILD,
                            (uintptr_t) this);
     destroy = res ? false : true;
     return res;
   }
+  int remember (bool detach)
+  {
+    int res = remember_without_attach (detach);
+    if (res && !detach)
+      res = reattach ();
+    return res;
+  }
 #endif
   HANDLE shared_handle () {return h;}
   HANDLE shared_winpid_handle () {return winpid_hdl;}
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 900facd58..9af47ce48 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -216,9 +216,7 @@ proc_subproc (DWORD what, uintptr_t val)
          vchild->process_state |= PID_INITIALIZING;
          vchild->ppid = what == PROC_DETACHED_CHILD ? 1 : myself->pid; /* 
always set last */
        }
-      if (what == PROC_DETACHED_CHILD)
-       break;
-      /* fall through intentionally */
+      break;
 
     case PROC_REATTACH_CHILD:
       procs[nprocs] = vchild;
-- 
2.21.0

Reply via email to