diff options
author | Christopher Faylor <me@cgf.cx> | 2001-04-01 00:06:17 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2001-04-01 00:06:17 +0000 |
commit | f611148366ee3934d16824f8a973177aaece0aa8 (patch) | |
tree | b27e26f288e5497966f358cb47783a1bff9a5d19 /winsup/cygwin/wait.cc | |
parent | ab57d1463946e37a5b7ce25498b3b42c3f617666 (diff) | |
download | newlib-f611148366ee3934d16824f8a973177aaece0aa8.zip newlib-f611148366ee3934d16824f8a973177aaece0aa8.tar.gz newlib-f611148366ee3934d16824f8a973177aaece0aa8.tar.bz2 |
* sigproc.h (class sigframe): Implement 'unregister()' method.
(sigframe::~sigframe): Use unregister method.
(sigframe::call_signal_handler): Declare new method.
* exceptions.cc (sigframe::call_signal_handler): New method. Unregisters
current sigframe before calling signal handler.
(setup_handler): Clear waiting threads prior to arming signal_arrived.
* syscalls.cc (_read): Change goto to loop. Recalculate sigframe inside of
loop so that constructor is called when appropriate.
* wait.cc (wait4): Ditto.
* signal.cc: Change "sig" to "signal" in debugging messages throughout.
* sigproc.cc: Ditto.
Diffstat (limited to 'winsup/cygwin/wait.cc')
-rw-r--r-- | winsup/cygwin/wait.cc | 123 |
1 files changed, 63 insertions, 60 deletions
diff --git a/winsup/cygwin/wait.cc b/winsup/cygwin/wait.cc index a5ed68c..0fa3005 100644 --- a/winsup/cygwin/wait.cc +++ b/winsup/cygwin/wait.cc @@ -50,71 +50,74 @@ wait4 (int intpid, int *status, int options, struct rusage *r) int res; waitq *w; HANDLE waitfor; - sigframe thisframe (mainthread); bool sawsig; -beg: - sawsig = 0; - if (options & ~(WNOHANG | WUNTRACED)) + while (1) { - set_errno (EINVAL); - return -1; + sigframe thisframe (mainthread); + sawsig = 0; + if (options & ~(WNOHANG | WUNTRACED)) + { + set_errno (EINVAL); + return -1; + } + + if (r) + memset (r, 0, sizeof (*r)); + + if ((w = (waitq *) waitq_storage.get ()) == NULL) + w = (waitq *) waitq_storage.create (); + + 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 = WaitForSingleObject (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); + sawsig = 1; + 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 || !thisframe.call_signal_handler ()) + break; } - if (r) - memset (r, 0, sizeof (*r)); - - if ((w = (waitq *) waitq_storage.get ()) == NULL) - w = (waitq *) waitq_storage.create (); - - 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 = WaitForSingleObject (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); - sawsig = 1; - 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 && call_signal_handler ()) - goto beg; sigproc_printf ("intpid %d, status %p, w->status %d, options %d, res %d", intpid, status, w->status, options, res); w->status = -1; |