* child_info.h (CURR_CHILD_INFO_MAGIC): Reset.

(child_info::rd_proc_pipe): Declare new field.
(child_info::wr_proc_pipe): Ditto.
(child_info::prefork): Declare new function, derived from previous pinfo
version.
* dcrt0.cc (child_info_fork::handle_fork): Close previous wr_proc_pipe when
appropriate and assign new one from passed-in child_info block.
(child_info_spawn::handle_spawn): Assign our wr_proc_pipe handle from passed-in
child_info block.
* fork.cc (child_info::prefork): Define new function.
(frok::child): Clear rd_proc_pipe and wr_proc_pipe so they will not be closed
by the child_info destructor.
(frok::parent): Use child_info prefork handling, outside of retry loop.  Set
rd_proc_pipe in child's pinfo after successful CreateProcess.  Eliminate
postfork call.
* globals.cc (my_wr_proc_pipe): Define/declare new variable.
* pinfo.cc (pinfo::pending_rd_proc_pipe): Delete.
(pinfo::pending_wr_proc_pipe): Ditto.
(pinfo::prefork): Ditto.
(pinfo::postfork): Ditto.
(pinfo::postexec): Ditto.
(pinfo::wait): Assume that rd_proc_pipe is set up correctly prior to call.
(_pinfo::alert_parent): Replace "wr_proc_pipe" with "my_wr_proc_pipe".
* pinfo.h (_pinfo::_wr_proc_pipe): Delete declaration.
(_pinfo::set_rd_proc_pipe): Define new function.
(pinfo::pending_rd_proc_pipe): Delete declaration.
(pinfo::pending_wr_proc_pipe): Ditto.
(pinfo::prefork): Ditto.
(pinfo::postfork): Ditto.
(pinfo::postexec): Ditto.
(pinfo::wr_proc_pipe): Ditto.
* sigproc.cc (child_info::child_info): Clear rd_proc_pipe and wr_proc_pipe.
(child_info::cleanup): Close rd_proc_pipe and wr_proc_pipe if necessary.
(child_info_fork::child_info_fork): Set forker_finished to NULL by default.
(child_info_spawn::child_info_spawn): Use my_wr_proc_pipe rather than
myself->wr_proc_pipe.
(child_info::sync): Ditto.
(child_info_spawn::cleanup): Call child_info::cleanup.
* spawn.cc (child_info_spawn::worker): Remove call to myself.prefork().  Set
wr_proc_pipe when execing or set up new rd_proc_pipe/wr_proc_pipe via
child_info::prefork when spawning.  Remove call to pinfo::postexec.  Set
rd_proc_pipe in child pinfo when spawning.  Use my_wr_proc_pipe rather than
myself->wr_proc_pipe.  Remove call to postfork.
This commit is contained in:
Christopher Faylor
2012-03-20 15:07:30 +00:00
parent e9a6f9c625
commit 1fb6667f1c
9 changed files with 148 additions and 111 deletions

View File

@@ -109,6 +109,25 @@ frok::error (const char *fmt, ...)
return true;
}
/* Set up a pipe which will track the life of a "pid" through
even after we've exec'ed. */
void
child_info::prefork (bool detached)
{
if (!detached)
{
if (!CreatePipe (&rd_proc_pipe, &wr_proc_pipe, &sec_none_nih, 16))
api_fatal ("prefork: couldn't create pipe process tracker%E");
if (!SetHandleInformation (wr_proc_pipe, HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT))
api_fatal ("prefork: couldn't set process pipe(%p) inherit state, %E",
wr_proc_pipe);
ProtectHandle1 (rd_proc_pipe, rd_proc_pipe);
ProtectHandle1 (wr_proc_pipe, wr_proc_pipe);
}
}
int __stdcall
frok::child (volatile char * volatile here)
{
@@ -194,6 +213,10 @@ frok::child (volatile char * volatile here)
ld_preload ();
fixup_hooks_after_fork ();
_my_tls.fixup_after_fork ();
/* Clear this or the destructor will close them. In the case of
rd_proc_pipe that would be an invalid handle. In the case of
wr_proc_pipe it would be == my_wr_proc_pipe. Both would be bad. */
ch.rd_proc_pipe = ch.wr_proc_pipe = NULL;
cygwin_finished_initializing = true;
return 0;
}
@@ -326,11 +349,11 @@ frok::parent (volatile char * volatile stack_here)
cygheap->user.deimpersonate ();
fix_impersonation = true;
ch.refresh_cygheap ();
ch.prefork (); /* set up process tracking pipes. */
while (1)
{
hchild = NULL;
myself.prefork ();
rc = CreateProcessW (myself->progname, /* image to run */
myself->progname, /* what we send in arg0 */
&sec_none_nih,
@@ -403,6 +426,7 @@ frok::parent (volatile char * volatile stack_here)
/* Fill in fields in the child's process table entry. */
child->dwProcessId = pi.dwProcessId;
child.hProcess = hchild;
child.set_rd_proc_pipe (ch.rd_proc_pipe);
/* Hopefully, this will succeed. The alternative to doing things this
way is to reserve space prior to calling CreateProcess and then fill
@@ -516,7 +540,6 @@ frok::parent (volatile char * volatile stack_here)
/* Common cleanup code for failure cases */
cleanup:
myself.postfork ();
if (fix_impersonation)
cygheap->user.reimpersonate ();
if (locked)