* 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

@@ -352,10 +352,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
if (mode == _P_OVERLAY)
chtype = _CH_EXEC;
else
{
chtype = _CH_SPAWN;
myself.prefork ();
}
chtype = _CH_SPAWN;
moreinfo = cygheap_exec_info::alloc ();
@@ -616,6 +613,12 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
&& fhandler_console::tc_getpgid () != myself->pgid)
c_flags |= CREATE_NEW_PROCESS_GROUP;
refresh_cygheap ();
if (chtype == _CH_EXEC)
wr_proc_pipe = my_wr_proc_pipe;
else
prefork ();
/* When ruid != euid we create the new process under the current original
account and impersonate in child, this way maintaining the different
effective vs. real ids.
@@ -737,6 +740,8 @@ loop:
myself->exec_sendsig = NULL;
}
myself->process_state &= ~PID_NOTCYGWIN;
if (wr_proc_pipe == my_wr_proc_pipe)
wr_proc_pipe = NULL; /* We still own it: don't nuke in destructor */
res = -1;
goto out;
}
@@ -771,18 +776,6 @@ loop:
myself.hProcess = hExeced = pi.hProcess;
real_path.get_wide_win32_path (myself->progname); // FIXME: race?
sigproc_printf ("new process name %W", myself->progname);
/* If wr_proc_pipe doesn't exist then this process was not started by a cygwin
process. So, we need to wait around until the process we've just "execed"
dies. Use our own wait facility below to wait for our own pid to exit
(there is some minor special case code in proc_waiter and friends to
accommodate this).
If wr_proc_pipe exists, then it will be inherited by the child.
If the child has exited already, that's ok. The parent will pick up
on this fact when we exit. myself.postexec () will close our end of
the pipe. */
if (!newargv.win16_exe && myself->wr_proc_pipe)
myself.postexec ();
pid = myself->pid;
if (!iscygwin ())
close_all_files ();
@@ -801,6 +794,7 @@ loop:
res = -1;
goto out;
}
child.set_rd_proc_pipe (rd_proc_pipe);
child->dwProcessId = pi.dwProcessId;
child.hProcess = pi.hProcess;
@@ -857,7 +851,7 @@ loop:
else
{
close_all_files (true);
if (!myself->wr_proc_pipe
if (!my_wr_proc_pipe
&& WaitForSingleObject (pi.hProcess, 0) == WAIT_TIMEOUT)
{
extern bool is_toplevel_proc;
@@ -887,8 +881,6 @@ loop:
}
out:
if (mode != _P_OVERLAY)
myself.postfork ();
this->cleanup ();
if (envblock)
free (envblock);