From 88127f1a62f6cff2453f306a1cb2984e6b8425cb Mon Sep 17 00:00:00 2001 From: Daniel Eischen Date: Fri, 28 Jun 2002 13:28:41 +0000 Subject: [PATCH] Make sigpending and sigsuspend account for signals that are pending on the process as well as pending on the current thread. Reported by: Andrew MacIntyre --- lib/libc_r/uthread/uthread_sigpending.c | 8 ++++++-- lib/libc_r/uthread/uthread_sigsuspend.c | 24 +++++++++++++++++++++--- lib/libkse/thread/thr_sigpending.c | 8 ++++++-- lib/libkse/thread/thr_sigsuspend.c | 24 +++++++++++++++++++++--- lib/libpthread/thread/thr_sigpending.c | 8 ++++++-- lib/libpthread/thread/thr_sigsuspend.c | 24 +++++++++++++++++++++--- 6 files changed, 81 insertions(+), 15 deletions(-) diff --git a/lib/libc_r/uthread/uthread_sigpending.c b/lib/libc_r/uthread/uthread_sigpending.c index 3c7efa43184a..5eaf6ff38e51 100644 --- a/lib/libc_r/uthread/uthread_sigpending.c +++ b/lib/libc_r/uthread/uthread_sigpending.c @@ -31,6 +31,9 @@ * * $FreeBSD$ */ +#include +#include +#include #include #include #include @@ -39,9 +42,9 @@ __weak_reference(_sigpending, sigpending); int -_sigpending(sigset_t * set) +_sigpending(sigset_t *set) { - struct pthread *curthread = _get_curthread(); + struct pthread *curthread = _get_curthread(); int ret = 0; /* Check for a null signal set pointer: */ @@ -51,6 +54,7 @@ _sigpending(sigset_t * set) } else { *set = curthread->sigpend; + SIGSETOR(*set, _process_sigpending); } /* Return the completion status: */ return (ret); diff --git a/lib/libc_r/uthread/uthread_sigsuspend.c b/lib/libc_r/uthread/uthread_sigsuspend.c index 120109789b49..42f174b262f5 100644 --- a/lib/libc_r/uthread/uthread_sigsuspend.c +++ b/lib/libc_r/uthread/uthread_sigsuspend.c @@ -32,6 +32,8 @@ * $FreeBSD$ */ #include +#include +#include #include #include #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; diff --git a/lib/libkse/thread/thr_sigpending.c b/lib/libkse/thread/thr_sigpending.c index 3c7efa43184a..5eaf6ff38e51 100644 --- a/lib/libkse/thread/thr_sigpending.c +++ b/lib/libkse/thread/thr_sigpending.c @@ -31,6 +31,9 @@ * * $FreeBSD$ */ +#include +#include +#include #include #include #include @@ -39,9 +42,9 @@ __weak_reference(_sigpending, sigpending); int -_sigpending(sigset_t * set) +_sigpending(sigset_t *set) { - struct pthread *curthread = _get_curthread(); + struct pthread *curthread = _get_curthread(); int ret = 0; /* Check for a null signal set pointer: */ @@ -51,6 +54,7 @@ _sigpending(sigset_t * set) } else { *set = curthread->sigpend; + SIGSETOR(*set, _process_sigpending); } /* Return the completion status: */ return (ret); diff --git a/lib/libkse/thread/thr_sigsuspend.c b/lib/libkse/thread/thr_sigsuspend.c index 120109789b49..42f174b262f5 100644 --- a/lib/libkse/thread/thr_sigsuspend.c +++ b/lib/libkse/thread/thr_sigsuspend.c @@ -32,6 +32,8 @@ * $FreeBSD$ */ #include +#include +#include #include #include #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; diff --git a/lib/libpthread/thread/thr_sigpending.c b/lib/libpthread/thread/thr_sigpending.c index 3c7efa43184a..5eaf6ff38e51 100644 --- a/lib/libpthread/thread/thr_sigpending.c +++ b/lib/libpthread/thread/thr_sigpending.c @@ -31,6 +31,9 @@ * * $FreeBSD$ */ +#include +#include +#include #include #include #include @@ -39,9 +42,9 @@ __weak_reference(_sigpending, sigpending); int -_sigpending(sigset_t * set) +_sigpending(sigset_t *set) { - struct pthread *curthread = _get_curthread(); + struct pthread *curthread = _get_curthread(); int ret = 0; /* Check for a null signal set pointer: */ @@ -51,6 +54,7 @@ _sigpending(sigset_t * set) } else { *set = curthread->sigpend; + SIGSETOR(*set, _process_sigpending); } /* Return the completion status: */ return (ret); diff --git a/lib/libpthread/thread/thr_sigsuspend.c b/lib/libpthread/thread/thr_sigsuspend.c index 120109789b49..42f174b262f5 100644 --- a/lib/libpthread/thread/thr_sigsuspend.c +++ b/lib/libpthread/thread/thr_sigsuspend.c @@ -32,6 +32,8 @@ * $FreeBSD$ */ #include +#include +#include #include #include #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;