diff options
Diffstat (limited to 'lib/libpthread/thread/thr_sigwait.c')
-rw-r--r-- | lib/libpthread/thread/thr_sigwait.c | 74 |
1 files changed, 61 insertions, 13 deletions
diff --git a/lib/libpthread/thread/thr_sigwait.c b/lib/libpthread/thread/thr_sigwait.c index 63c7093..f441fa3 100644 --- a/lib/libpthread/thread/thr_sigwait.c +++ b/lib/libpthread/thread/thr_sigwait.c @@ -39,24 +39,72 @@ int sigwait(const sigset_t * set, int *sig) { - int ret; - int status; - sigset_t oset; + int ret = 0; + int i; + sigset_t oset; + struct sigaction act; + + /* + * Specify the thread kernel signal handler. + */ + act.sa_handler = (void (*) ()) _thread_sig_handler; + act.sa_flags = SA_RESTART; + act.sa_mask = *set; - /* Save the current sigmal mask: */ - oset = _thread_run->sigmask; + /* + * These signals can't be waited on. + */ + sigdelset(&act.sa_mask, SIGKILL); + sigdelset(&act.sa_mask, SIGSTOP); + sigdelset(&act.sa_mask, SIGVTALRM); + sigdelset(&act.sa_mask, SIGCHLD); + sigdelset(&act.sa_mask, SIGINFO); - /* Combine the caller's mask with the current one: */ - _thread_run->sigmask |= *set; + /* + * Enter a loop to find the signals that are SIG_DFL. For + * these signals we must install a dummy signal handler in + * order for the kernel to pass them in to us. POSIX says + * that the application must explicitly install a dummy + * handler for signals that are SIG_IGN in order to sigwait + * on them, so we ignore SIG_IGN signals. + */ + for (i = 1; i < NSIG; i++) { + if (sigismember(&act.sa_mask, i)) { + if (_thread_sigact[i - 1].sa_handler == SIG_DFL) { + if (_thread_sys_sigaction(i,&act,NULL) != 0) + ret = -1; + } + else if (_thread_sigact[i - 1].sa_handler == SIG_IGN) + sigdelset(&act.sa_mask, i); + } + } + if (ret == 0) { - /* Wait for a signal: */ - _thread_kern_sched_state(PS_SIGWAIT, __FILE__, __LINE__); + /* Save the current signal mask: */ + oset = _thread_run->sigmask; - /* Return the signal number to the caller: */ - *sig = _thread_run->signo; + /* Combine the caller's mask with the current one: */ + _thread_run->sigmask |= act.sa_mask; - /* Restore the signal mask: */ - _thread_run->sigmask = oset; + /* Wait for a signal: */ + _thread_kern_sched_state(PS_SIGWAIT, __FILE__, __LINE__); + + /* Return the signal number to the caller: */ + *sig = _thread_run->signo; + + /* Restore the signal mask: */ + _thread_run->sigmask = oset; + } + + /* Restore the sigactions: */ + act.sa_handler = SIG_DFL; + for (i = 1; i < NSIG; i++) { + if (sigismember(&act.sa_mask, i) && + (_thread_sigact[i - 1].sa_handler == SIG_DFL)) { + if (_thread_sys_sigaction(i,&act,NULL) != 0) + ret = -1; + } + } /* Return the completion status: */ return (ret); |