aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/pinfo.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-12-05 19:41:26 +0000
committerChristopher Faylor <me@cgf.cx>2004-12-05 19:41:26 +0000
commit54dd79bb44d2180ab769558deab274c70391cca7 (patch)
tree344f9e32353901bd9274239beb32c35ad941e414 /winsup/cygwin/pinfo.cc
parentd54b79d3514106b603a2811eadf9b265e2af90d3 (diff)
downloadnewlib-54dd79bb44d2180ab769558deab274c70391cca7.zip
newlib-54dd79bb44d2180ab769558deab274c70391cca7.tar.gz
newlib-54dd79bb44d2180ab769558deab274c70391cca7.tar.bz2
* sigproc.cc (mychild): Reimplement as list scan.
(proc_subproc): Don't mess with pinfo if it's myself. * child_info.h (child_info_types): Label enum for _PROC constants. (child_info::child_info): New constructor. (child_info::~child_info): New destructor. (child_info::sync): Declare new function. (child_info_fork::child_info_fork): New constructor. (child_info_spawn::child_info_spawn): Remove old constructor. (child_info_spawn::child_info_spawn): New constructor. * dcrt0.cc (dll_crt0_0): Use correct sizeof when doing sanity check on passed in child_info. Signal readiness to parent when not forking (and not spawning). * fork.cc (sync_with_child): Delete. (resume_child): Remove extra argument. (sync_with_parent): Use child_info method to sync with parent. (fork_child): Don't close fork_info->subproc_ready since that is now handled by the destructor. (fork_parent): Remove subproc_ready stuff. Use child_info sync method for waiting.. Set start time here for child. Rename "forked" to "child". (fork): Check ch.subproc_ready for validity here. * pinfo.h (_pinfo::exec_sendsig): Temp storage for exec stub which may be staying around to handle non-cygwin captive process. (_pinfo::exec_dwProcessId): Ditto. (_pinfo::_lock): Renamed from lock. (_pinfo::lock): New method. (_pinfo::unlock): Ditto. (_pinfo::initialize_lock): Ditto. * pinfo.cc (set_myself): Use initialize_lock method to initialize myself lock. Set "exec" fields in _pinfo to zero to indicate that we've started successfully. Set start time here when appropriate. (_pinfo::commune_send): Use pinfo lock/unlock methods. (proc_waiter): Remove special case for non-cywin processes. Reinstitute handling for PID_NOCLDSTOP. * sigproc.cc (proc_subproc): Set proper EAGAIN errno when process table is filled. (sig_send): Use exec_* fields from _pinfo for sending signals if the the _pinfo sendsig never materializes. (child_info::child_info): New constructor, renamed from init_child_info. Zeroes child_info structure and sets appropriate fields in structure based on chtype. (child_info::~child_info): New destructor. Closes subproc_ready if it exists. (child_info_fork::child_info_fork): New constructor. (child_info_spawn::child_info_spawn): New constructor. (child_info::ready): New function. Signals parent when child is ready. (child_info::sync): New function. Wait for child to signal us or process to die. (remove_proc): Remove closing of hProcess since this should now be handled shortly after process creation. * spawn.cc (spawn_guts): Use child_info_spawn constructor rather than init_child_info. Save exec_sendsig and exec_dwProcessId in execing _pinfo. Rely on child_info constructor to properly set parent_wr_proc_pipe in ciresrv. Revert to previous determination on whether to start a process in suspended mode. Remove reparenting stuff. Just keep a stub around if starting a non-cygwin process.
Diffstat (limited to 'winsup/cygwin/pinfo.cc')
-rw-r--r--winsup/cygwin/pinfo.cc81
1 files changed, 46 insertions, 35 deletions
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 62dd63d..ebc6d07 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -50,21 +50,25 @@ set_myself (HANDLE h)
cygheap->pid = cygwin_pid (GetCurrentProcessId ());
myself.init (cygheap->pid, PID_IN_USE | PID_MYSELF, h);
myself->process_state |= PID_IN_USE;
- myself->start_time = time (NULL); /* Register our starting time. */
+ myself->dwProcessId = GetCurrentProcessId ();
(void) GetModuleFileName (NULL, myself->progname, sizeof (myself->progname));
if (!strace.active)
strace.hello ();
debug_printf ("myself->dwProcessId %u", myself->dwProcessId);
- InitializeCriticalSection (&myself.lock);
- myself->dwProcessId = GetCurrentProcessId ();
+ myself.initialize_lock ();
if (h)
{
/* here if execed */
static pinfo NO_COPY myself_identity;
myself_identity.init (cygwin_pid (myself->dwProcessId), PID_EXECED);
+ myself->start_time = time (NULL); /* Register our starting time. */
+ myself->exec_sendsig = NULL;
+ myself->exec_dwProcessId = 0;
}
- else if (myself->wr_proc_pipe)
+ else if (!myself->wr_proc_pipe)
+ myself->start_time = time (NULL); /* Register our starting time. */
+ else
{
/* We've inherited the parent's wr_proc_pipe. We don't need it,
so close it. */
@@ -522,7 +526,7 @@ _pinfo::commune_send (DWORD code, ...)
__seterrno ();
goto err;
}
- EnterCriticalSection (&myself.lock);
+ myself.lock ();
myself->tothem = tome;
myself->fromthem = fromme;
myself->hello_pid = pid;
@@ -626,7 +630,7 @@ err:
out:
myself->hello_pid = 0;
- LeaveCriticalSection (&myself.lock);
+ myself.unlock ();
return res;
}
@@ -710,13 +714,6 @@ proc_waiter (void *arg)
/* Child exited. Do some cleanup and signal myself. */
CloseHandle (vchild.rd_proc_pipe);
vchild.rd_proc_pipe = NULL;
-
- if (vchild->process_state != PID_EXITED && vchild.hProcess)
- {
- DWORD exit_code;
- if (GetExitCodeProcess (vchild.hProcess, &exit_code))
- vchild->exitcode = (exit_code & 0xff) << 8;
- }
if (WIFEXITED (vchild->exitcode))
si.si_sigval.sival_int = CLD_EXITED;
else if (WCOREDUMP (vchild->exitcode))
@@ -730,33 +727,13 @@ proc_waiter (void *arg)
case SIGTTOU:
case SIGTSTP:
case SIGSTOP:
+ if (ISSTATE (myself, PID_NOCLDSTOP)) // FIXME: No need for this flag to be in _pinfo any longer
+ continue;
/* Child stopped. Signal myself. */
si.si_sigval.sival_int = CLD_STOPPED;
break;
case SIGCONT:
continue;
- case __ALERT_REPARENT: /* sigh */
- /* spawn_guts has signalled us that it has just started a new
- subprocess which will take over this cygwin pid. */
-
- /* We need to keep a handle to the original windows process which
- represents the cygwin process around to make sure that the
- windows pid is not reused before we are through with it.
- So, detect the first time that a subprocess calls exec
- and save the current hprocess in the pid_handle field.
- On subsequent execs just close the handle. */
- if (!vchild.hProcess)
- /* something went wrong. oh well. */;
- else if (vchild.pid_handle)
- ForceCloseHandle1 (vchild.hProcess, childhProc);
- else
- vchild.pid_handle = vchild.hProcess;
- vchild.hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE,
- vchild->dwProcessId);
- vchild->cygstarted++;
- if (vchild.hProcess)
- ProtectHandle1 (vchild.hProcess, childhProc);
- continue;
default:
system_printf ("unknown value %d on proc pipe", buf);
continue;
@@ -790,6 +767,40 @@ proc_waiter (void *arg)
return 0;
}
+void
+proc_pipe::set (bool closeem)
+{
+ myself.lock ();
+ if (!CreatePipe (&in, &out, &sec_none_nih, 16))
+ {
+ system_printf ("couldn't create pipe, %E");
+ return;
+ }
+ /* Duplicate the write end of the pipe into the subprocess. Make it inheritable
+ so that all of the execed children get it. */
+ if (!DuplicateHandle (hMainProc, out, hMainProc, &out, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
+ {
+ CloseHandle (in);
+ in = out = NULL;
+ system_printf ("couldn't make handle %p noninheritable, %E", out);
+ return;
+ }
+ _closeem = closeem;
+}
+
+proc_pipe::~proc_pipe ()
+{
+ if (_closeem)
+ {
+ if (in)
+ CloseHandle (in);
+ if (out)
+ CloseHandle (out);
+ }
+ myself.unlock ();
+}
+
/* function to set up the process pipe and kick off proc_waiter */
int
pinfo::wait ()