4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 12:29:32 +08:00

* fork.cc (fork_parent): Reinstate "childhProc" protection. Don't close

hProcess handle here since it is used to ensure that a new process isn't
created with the old pid after the old pid exits.
* spawn.cc (spawn_guts): Ditto.
* pinfo.cc (proc_waiter): Don't send any signals if we've execed since this
process doesn't officially exist.
* pinfo.h (pinfo::pid_handle): Eliminate.  Just use hProc.
* sigproc.cc (sig_send): Don't send any signals if our sendsig doesn't exist.
That's a sign that we are execing.
(remove_proc): Eliminate pid_handle close.
This commit is contained in:
Christopher Faylor 2004-12-06 00:29:41 +00:00
parent 013f043fff
commit 8c43a9f82e
6 changed files with 25 additions and 16 deletions

View File

@ -1,3 +1,16 @@
2004-12-05 Christopher Faylor <cgf@timesys.com>
* fork.cc (fork_parent): Reinstate "childhProc" protection. Don't
close hProcess handle here since it is used to ensure that a new
process isn't created with the old pid after the old pid exits.
* spawn.cc (spawn_guts): Ditto.
* pinfo.cc (proc_waiter): Don't send any signals if we've execed since
this process doesn't officially exist.
* pinfo.h (pinfo::pid_handle): Eliminate. Just use hProc.
* sigproc.cc (sig_send): Don't send any signals if our sendsig doesn't
exist. That's a sign that we are execing.
(remove_proc): Eliminate pid_handle close.
2004-12-05 Christopher Faylor <cgf@timesys.com> 2004-12-05 Christopher Faylor <cgf@timesys.com>
* cygthread.h (cygthread::terminate_thread): Make public. * cygthread.h (cygthread::terminate_thread): Make public.

View File

@ -402,7 +402,7 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
ProtectHandle (pi.hThread); ProtectHandle (pi.hThread);
/* Protect the handle but name it similarly to the way it will /* Protect the handle but name it similarly to the way it will
be called in subproc handling. */ be called in subproc handling. */
ProtectHandle (pi.hProcess); ProtectHandle1 (pi.hProcess, childhProc);
/* Fill in fields in the child's process table entry. */ /* Fill in fields in the child's process table entry. */
child->dwProcessId = pi.dwProcessId; child->dwProcessId = pi.dwProcessId;
@ -501,7 +501,6 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
(void) resume_child (forker_finished); (void) resume_child (forker_finished);
} }
ForceCloseHandle (pi.hProcess);
ForceCloseHandle (pi.hThread); ForceCloseHandle (pi.hThread);
ForceCloseHandle (forker_finished); ForceCloseHandle (forker_finished);
forker_finished = NULL; forker_finished = NULL;

View File

@ -742,7 +742,7 @@ proc_waiter (void *arg)
/* Special case: If the "child process" that died is us, then we're /* Special case: If the "child process" that died is us, then we're
execing. Just call proc_subproc directly and then exit this loop. execing. Just call proc_subproc directly and then exit this loop.
We're done here. */ We're done here. */
if (hExeced && vchild->pid == myself->pid) if (hExeced)
{ {
/* execing. no signals available now. */ /* execing. no signals available now. */
proc_subproc (PROC_CLEARWAIT, 0); proc_subproc (PROC_CLEARWAIT, 0);

View File

@ -136,13 +136,12 @@ public:
HANDLE hProcess; HANDLE hProcess;
CRITICAL_SECTION _lock; CRITICAL_SECTION _lock;
/* Handle associated with initial Windows pid which started it all. */ /* Handle associated with initial Windows pid which started it all. */
HANDLE pid_handle;
class cygthread *wait_thread; class cygthread *wait_thread;
void init (pid_t, DWORD, HANDLE = NULL) __attribute__ ((regparm(3))); void init (pid_t, DWORD, HANDLE = NULL) __attribute__ ((regparm(3)));
pinfo () {} pinfo () {}
pinfo (_pinfo *x): procinfo (x), hProcess (NULL), pid_handle (NULL) {} pinfo (_pinfo *x): procinfo (x), hProcess (NULL) {}
pinfo (pid_t n) : rd_proc_pipe (NULL), hProcess (NULL), pid_handle (NULL) {init (n, 0);} pinfo (pid_t n) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, 0);}
pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL), pid_handle (NULL) {init (n, flag);} pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, flag);}
void release (); void release ();
int wait () __attribute__ ((regparm (1))); int wait () __attribute__ ((regparm (1)));
~pinfo () ~pinfo ()

View File

@ -82,6 +82,8 @@ static bool __stdcall remove_proc (int);
static bool __stdcall stopped_or_terminated (waitq *, _pinfo *); static bool __stdcall stopped_or_terminated (waitq *, _pinfo *);
static DWORD WINAPI wait_sig (VOID *arg); static DWORD WINAPI wait_sig (VOID *arg);
extern HANDLE hExeced;
/* wait_sig bookkeeping */ /* wait_sig bookkeeping */
class pending_signals class pending_signals
@ -501,7 +503,6 @@ sigproc_init ()
void __stdcall void __stdcall
sigproc_terminate (void) sigproc_terminate (void)
{ {
extern HANDLE hExeced;
hwait_sig = NULL; hwait_sig = NULL;
if (myself->sendsig == INVALID_HANDLE_VALUE) if (myself->sendsig == INVALID_HANDLE_VALUE)
@ -509,7 +510,6 @@ sigproc_terminate (void)
else else
{ {
sigproc_printf ("entering"); sigproc_printf ("entering");
// finished with anything it is doing
if (!hExeced) if (!hExeced)
{ {
HANDLE sendsig = myself->sendsig; HANDLE sendsig = myself->sendsig;
@ -545,6 +545,9 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
sigpacket pack; sigpacket pack;
pack.wakeup = NULL; pack.wakeup = NULL;
if (!myself->sendsig) // FIXME: This catches the exec case but what if the exec is going to fail?
goto out;
bool wait_for_completion; bool wait_for_completion;
if (!(its_me = (p == NULL || p == myself || p == myself_nowait))) if (!(its_me = (p == NULL || p == myself || p == myself_nowait)))
wait_for_completion = false; wait_for_completion = false;
@ -657,7 +660,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
{ {
if (no_signals_available ()) if (no_signals_available ())
sigproc_printf ("I'm going away now"); sigproc_printf ("I'm going away now");
else else if (!hExeced)
system_printf ("error sending signal %d to pid %d, pipe handle %p, %E", system_printf ("error sending signal %d to pid %d, pipe handle %p, %E",
si.si_signo, p->pid, sendsig); si.si_signo, p->pid, sendsig);
} }
@ -857,8 +860,6 @@ remove_proc (int ci)
if (procs[ci] != myself) if (procs[ci] != myself)
{ {
procs[ci].release (); procs[ci].release ();
if (procs[ci].pid_handle)
ForceCloseHandle1 (procs[ci].pid_handle, childhProc);
if (procs[ci].hProcess) if (procs[ci].hProcess)
ForceCloseHandle1 (procs[ci].hProcess, childhProc); ForceCloseHandle1 (procs[ci].hProcess, childhProc);
} }

View File

@ -784,7 +784,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
rc ? cygpid : (unsigned int) -1, prog_arg, one_line.buf); rc ? cygpid : (unsigned int) -1, prog_arg, one_line.buf);
/* Name the handle similarly to proc_subproc. */ /* Name the handle similarly to proc_subproc. */
ProtectHandle (pi.hProcess); ProtectHandle1 (pi.hProcess, childhProc);
bool wait_for_myself = false; bool wait_for_myself = false;
if (mode == _P_OVERLAY) if (mode == _P_OVERLAY)
@ -802,7 +802,6 @@ spawn_guts (const char * prog_arg, const char *const *argv,
this). */ this). */
if (!myself->wr_proc_pipe) if (!myself->wr_proc_pipe)
{ {
myself.hProcess = pi.hProcess;
myself.remember (); myself.remember ();
wait_for_myself = true; wait_for_myself = true;
myself->wr_proc_pipe = INVALID_HANDLE_VALUE; myself->wr_proc_pipe = INVALID_HANDLE_VALUE;
@ -855,8 +854,6 @@ if (wait_for_myself)
else else
ciresrv.sync (myself, INFINITE); ciresrv.sync (myself, INFINITE);
ForceCloseHandle (pi.hProcess);
switch (mode) switch (mode)
{ {
case _P_OVERLAY: case _P_OVERLAY: