diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2011-12-27 17:37:00 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2011-12-27 17:37:00 +0000 |
commit | 51f3ab9d216ddbbcac163c3af811a366a96976ad (patch) | |
tree | ac9da699edd4ef71e2c8ea66971ca5f4f4b9d91b /lib | |
parent | a88170e5760771d010055f5bfcdb3c08a73c6955 (diff) |
Don't let applications block, wait for, or handle SIGTHR, as the
thread library uses it internally for cancellation.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/librthread/rthread_cancel.c | 6 | ||||
-rw-r--r-- | lib/librthread/rthread_sig.c | 37 |
2 files changed, 39 insertions, 4 deletions
diff --git a/lib/librthread/rthread_cancel.c b/lib/librthread/rthread_cancel.c index 9877c607fd1..3dd34da68a0 100644 --- a/lib/librthread/rthread_cancel.c +++ b/lib/librthread/rthread_cancel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_cancel.c,v 1.1 2011/12/05 04:02:03 guenther Exp $ */ +/* $OpenBSD: rthread_cancel.c,v 1.2 2011/12/27 17:36:59 guenther Exp $ */ /* $snafu: libc_tag.c,v 1.4 2004/11/30 07:00:06 marc Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ @@ -453,10 +453,12 @@ int sigsuspend(const sigset_t *sigmask) { pthread_t self = pthread_self(); + sigset_t set = *sigmask; int rv; + sigdelset(&set, SIGTHR); _enter_cancel(self); - rv = _thread_sys_sigsuspend(sigmask); + rv = _thread_sys_sigsuspend(&set); _leave_cancel(self); return (rv); } diff --git a/lib/librthread/rthread_sig.c b/lib/librthread/rthread_sig.c index eea1306dc49..11351ddafc3 100644 --- a/lib/librthread/rthread_sig.c +++ b/lib/librthread/rthread_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sig.c,v 1.10 2011/12/05 04:02:03 guenther Exp $ */ +/* $OpenBSD: rthread_sig.c,v 1.11 2011/12/27 17:36:59 guenther Exp $ */ /* * Copyright (c) 2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -26,6 +26,8 @@ #include "rthread.h" +int _thread_sys_sigprocmask(int, const sigset_t *, sigset_t *); + int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset) { @@ -33,13 +35,28 @@ pthread_sigmask(int how, const sigset_t *set, sigset_t *oset) } int +sigprocmask(int how, const sigset_t *set, sigset_t *oset) +{ + sigset_t s; + + if (set != NULL && how != SIG_UNBLOCK && sigismember(set, SIGTHR)) { + s = *set; + sigdelset(&s, SIGTHR); + set = &s; + } + return (_thread_sys_sigprocmask(how, set, oset)); +} + +int sigwait(const sigset_t *set, int *sig) { pthread_t self = pthread_self(); + sigset_t s = *set; int ret; + sigdelset(&s, SIGTHR); _enter_cancel(self); - ret = thrsigdivert(*set, NULL, NULL); + ret = thrsigdivert(s, NULL, NULL); _leave_cancel(self); if (ret == -1) return (errno); @@ -47,3 +64,19 @@ sigwait(const sigset_t *set, int *sig) return (0); } +int +sigaction(int sig, const struct sigaction *act, struct sigaction *oact) +{ + struct sigaction sa; + + if (sig == SIGTHR) { + errno = EINVAL; + return (-1); + } + if (act != NULL && sigismember(&act->sa_mask, SIGTHR)) { + sa = *act; + sigdelset(&sa.sa_mask, SIGTHR); + act = &sa; + } + return (_thread_sys_sigaction(sig, act, oact)); +} |