diff options
Diffstat (limited to 'lib/libc_r/uthread/uthread_sigsuspend.c')
-rw-r--r-- | lib/libc_r/uthread/uthread_sigsuspend.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/libc_r/uthread/uthread_sigsuspend.c b/lib/libc_r/uthread/uthread_sigsuspend.c index 1201097..42f174b 100644 --- a/lib/libc_r/uthread/uthread_sigsuspend.c +++ b/lib/libc_r/uthread/uthread_sigsuspend.c @@ -32,6 +32,8 @@ * $FreeBSD$ */ #include <signal.h> +#include <sys/param.h> +#include <sys/signalvar.h> #include <errno.h> #include <pthread.h> #include "pthread_private.h" @@ -43,7 +45,7 @@ _sigsuspend(const sigset_t * set) { struct pthread *curthread = _get_curthread(); int ret = -1; - sigset_t oset; + sigset_t oset, sigset; /* Check if a new signal set was provided by the caller: */ if (set != NULL) { @@ -53,8 +55,24 @@ _sigsuspend(const sigset_t * set) /* Change the caller's mask: */ curthread->sigmask = *set; - /* Wait for a signal: */ - _thread_kern_sched_state(PS_SIGSUSPEND, __FILE__, __LINE__); + /* + * Check if there are pending signals for the running + * thread or process that aren't blocked: + */ + sigset = curthread->sigpend; + SIGSETOR(sigset, _process_sigpending); + SIGSETNAND(sigset, curthread->sigmask); + if (SIGNOTEMPTY(sigset)) { + /* + * Call the kernel scheduler which will safely + * install a signal frame for the running thread: + */ + _thread_kern_sched_sig(); + } else { + /* Wait for a signal: */ + _thread_kern_sched_state(PS_SIGSUSPEND, + __FILE__, __LINE__); + } /* Always return an interrupted error: */ errno = EINTR; |