diff options
author | Christopher Faylor <me@cgf.cx> | 2004-12-23 14:57:08 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2004-12-23 14:57:08 +0000 |
commit | 4ee52924a61bdb2fd8ce7b64d111cf7df4d19fe3 (patch) | |
tree | 18464135531157edc28ecc4f73a7210511638611 /winsup/cygwin/spawn.cc | |
parent | 3993374d4ee8a081056fad98ebed90975970ccee (diff) | |
download | cygnal-4ee52924a61bdb2fd8ce7b64d111cf7df4d19fe3.tar.gz cygnal-4ee52924a61bdb2fd8ce7b64d111cf7df4d19fe3.tar.bz2 cygnal-4ee52924a61bdb2fd8ce7b64d111cf7df4d19fe3.zip |
* cygthread.cc (cygthread::stub): Detect if thread function wants to release
itself here, to avoid a race.
(cygthread::release): Clear more stuff. Add a diagnostic for an internal
error.
* cygthread.h (auto_release): New function.
* pinfo.h (pinfo::remember): Add an argument to denote whether child is
detached.
* fork.cc (fork_parent): Reflect change in arguments to pinfo::remember.
* pinfo.cc (_pinfo::exit): Signal exit more forcibly.
(proc_waiter): Use cygthread::auto_release to signify that cygthread::stub
should release the thread. This should avoid a race.
(pinfo::alert_parent): Don't signify an error when wr_proc_pipe == NULL.
* sigproc.cc (proc_subproc): Add support for PROC_DETACHED_CHILD.
* sigproc.h: Ditto.
* spawn.cc (spawn_guts): Specify whether child is detached or not when calling
pinfo::remember.
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r-- | winsup/cygwin/spawn.cc | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 587c963cc..1c84fad4e 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -802,7 +802,7 @@ spawn_guts (const char * prog_arg, const char *const *argv, this). */ if (!myself->wr_proc_pipe) { - myself.remember (); + myself.remember (true); wait_for_myself = true; myself->wr_proc_pipe = INVALID_HANDLE_VALUE; } @@ -822,14 +822,6 @@ spawn_guts (const char * prog_arg, const char *const *argv, } child->dwProcessId = pi.dwProcessId; child.hProcess = pi.hProcess; - if (!child.remember ()) - { - /* FIXME: Child in strange state now. */ - CloseHandle (pi.hProcess); - CloseHandle (pi.hThread); - res = -1; - goto out; - } strcpy (child->progname, real_path); /* FIXME: This introduces an unreferenced, open handle into the child. @@ -839,9 +831,15 @@ spawn_guts (const char * prog_arg, const char *const *argv, However, we should try to find another way to do this eventually. */ (void) DuplicateHandle (hMainProc, child.shared_handle (), pi.hProcess, NULL, 0, 0, DUPLICATE_SAME_ACCESS); - if (mode == _P_DETACH) - myself.alert_parent (0); child->start_time = time (NULL); /* Register child's starting time. */ + if (!child.remember (mode == _P_DETACH)) + { + /* FIXME: Child in strange state now */ + CloseHandle (pi.hProcess); + ForceCloseHandle (pi.hThread); + res = -1; + goto out; + } } /* Start the child running */ @@ -867,7 +865,7 @@ switch (mode) res = -1; break; case _P_DETACH: - res = 0; /* Lose all memory of this child. */ + res = 0; /* Lost all memory of this child. */ break; case _P_NOWAIT: case _P_NOWAITO: |