9863b78e7b
(_cygtls::wq): Declare. * cygtls.cc (_cygtls::fixup_after_fork): Clear wq.thread_ev to avoid using an invalid event handle in forked process. * dcrt0.cc (waitq_storage): Delete. (threadstuff): Remove waitq_storage. * perthread.h (per_thread_waitq): Delete. (waitq_storage): Delete declaration. * sigproc.cc (sigproc_init): Remove perthread waitq consideration. * sigproc.h (waitq): Delete declaration. * wait.cc (wait4): Use _my_tls waitq structure rather than per_thread. * cygtls.h (_cygtls::newmask): Delete member. (_cygtls::deltamask): New member. * gendef (_sigdelayed): Replace the call to set_process_mask by a call to set_process_mask_delta. * exceptions.cc (handle_sigsuspend): Do not filter tempmask. Or SIG_NONMASKABLE in deltamask as a flag. (_cygtls::interrupt_setup): Set deltamask only. (set_process_mask_delta): New function. (_cygtls::call_signal_handler): Replace the first call to set_process_mask by a call to set_process_mask_delta. * tlsoffsets.h: Regenerate.
128 lines
2.7 KiB
C++
128 lines
2.7 KiB
C++
/* wait.cc: Posix wait routines.
|
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#include "winsup.h"
|
|
#include <sys/wait.h>
|
|
#include <stdlib.h>
|
|
#include "cygerrno.h"
|
|
#include "sigproc.h"
|
|
#include "perthread.h"
|
|
#include "thread.h"
|
|
#include "cygtls.h"
|
|
|
|
/* This is called _wait and not wait because the real wait is defined
|
|
in libc/syscalls/syswait.c. It calls us. */
|
|
|
|
extern "C" pid_t
|
|
wait (int *status)
|
|
{
|
|
return wait4 (-1, status, 0, NULL);
|
|
}
|
|
|
|
extern "C" pid_t
|
|
waitpid (pid_t intpid, int *status, int options)
|
|
{
|
|
return wait4 (intpid, status, options, NULL);
|
|
}
|
|
|
|
extern "C" pid_t
|
|
wait3 (int *status, int options, struct rusage *r)
|
|
{
|
|
return wait4 (-1, status, options, r);
|
|
}
|
|
|
|
/* Wait for any child to complete.
|
|
* Note: this is not thread safe. Use of wait in multiple threads will
|
|
* not work correctly.
|
|
*/
|
|
|
|
extern "C" pid_t
|
|
wait4 (int intpid, int *status, int options, struct rusage *r)
|
|
{
|
|
int res;
|
|
HANDLE waitfor;
|
|
waitq *w;
|
|
|
|
pthread_testcancel ();
|
|
|
|
while (1)
|
|
{
|
|
sig_dispatch_pending ();
|
|
bool sawsig = false;
|
|
if (options & ~(WNOHANG | WUNTRACED))
|
|
{
|
|
set_errno (EINVAL);
|
|
return -1;
|
|
}
|
|
|
|
if (r)
|
|
memset (r, 0, sizeof (*r));
|
|
|
|
w = &_my_tls.wq;
|
|
|
|
w->pid = intpid;
|
|
w->options = options;
|
|
w->rusage = r;
|
|
sigproc_printf ("calling proc_subproc, pid %d, options %d",
|
|
w->pid, w->options);
|
|
if (!proc_subproc (PROC_WAIT, (DWORD) w))
|
|
{
|
|
set_errno (ENOSYS);
|
|
paranoid_printf ("proc_subproc returned 0");
|
|
res = -1;
|
|
goto done;
|
|
}
|
|
|
|
if ((waitfor = w->ev) == NULL)
|
|
goto nochildren;
|
|
|
|
res = pthread::cancelable_wait (waitfor, INFINITE);
|
|
|
|
sigproc_printf ("%d = WaitForSingleObject (...)", res);
|
|
|
|
if (w->ev == NULL)
|
|
{
|
|
nochildren:
|
|
/* found no children */
|
|
set_errno (ECHILD);
|
|
res = -1;
|
|
goto done;
|
|
}
|
|
|
|
if (w->status == -1)
|
|
{
|
|
set_sig_errno (EINTR);
|
|
_my_tls.call_signal_handler ();
|
|
sawsig = true;
|
|
res = -1;
|
|
}
|
|
else if (res != WAIT_OBJECT_0)
|
|
{
|
|
/* We shouldn't set errno to any random value if we can help it.
|
|
See the Posix manual for a list of valid values for `errno'. */
|
|
set_errno (EINVAL);
|
|
res = -1;
|
|
}
|
|
else if ((res = w->pid) != 0 && status)
|
|
*status = w->status;
|
|
|
|
done:
|
|
if (!sawsig || !_my_tls.call_signal_handler ())
|
|
break;
|
|
}
|
|
|
|
sigproc_printf ("intpid %d, status %p, w->status %d, options %d, res %d",
|
|
intpid, status, w->status, options, res);
|
|
w->status = -1;
|
|
if (res < 0)
|
|
sigproc_printf ("*** errno = %d", get_errno ());
|
|
return res;
|
|
}
|