summaryrefslogtreecommitdiffstats
path: root/lib/libc/thread/rthread_sync.c
diff options
context:
space:
mode:
authorpirofti <pirofti@openbsd.org>2018-04-24 16:28:42 +0000
committerpirofti <pirofti@openbsd.org>2018-04-24 16:28:42 +0000
commitbda456ccd11759e253796707fd980cfc75ecc76d (patch)
treeb010de26d6610adb828989702c7b32def9192bc8 /lib/libc/thread/rthread_sync.c
parentPush NET_LOCK down in the default ifioctl case. (diff)
downloadwireguard-openbsd-bda456ccd11759e253796707fd980cfc75ecc76d.tar.xz
wireguard-openbsd-bda456ccd11759e253796707fd980cfc75ecc76d.zip
Validate timespec and return ECANCELED when interrupted with SA_RESTART.
Discussing with mpi@ and guenther@, we decided to first fix the existing semaphore implementation with regards to SA_RESTART and POSIX compliant returns in the case where we deal with restartable signals. Currently we return EINTR everywhere which is mostly incorrect as the user can not know if she needs to recall the syscall or not. Return ECANCELED to signal that SA_RESTART was set and EINTR otherwise. Regression tests pass and so does the posixsuite. Timespec validation bits are needed to pass the later. OK mpi@, guenther@
Diffstat (limited to 'lib/libc/thread/rthread_sync.c')
-rw-r--r--lib/libc/thread/rthread_sync.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libc/thread/rthread_sync.c b/lib/libc/thread/rthread_sync.c
index 91ce55cbcf9..42e1a7ee737 100644
--- a/lib/libc/thread/rthread_sync.c
+++ b/lib/libc/thread/rthread_sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sync.c,v 1.4 2017/09/05 02:40:54 guenther Exp $ */
+/* $OpenBSD: rthread_sync.c,v 1.5 2018/04/24 16:28:42 pirofti Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* Copyright (c) 2012 Philip Guenther <guenther@openbsd.org>
@@ -375,7 +375,8 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp,
* cancellation) then we should just go back to
* sleep without changing state (timeouts, etc).
*/
- if (error == EINTR && (tib->tib_canceled == 0 ||
+ if ((error == EINTR || error == ECANCELED) &&
+ (tib->tib_canceled == 0 ||
(tib->tib_cantcancel & CANCEL_DISABLED))) {
_spinlock(&mutex->lock);
continue;
@@ -514,7 +515,8 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp)
* cancellation) then we should just go back to
* sleep without changing state (timeouts, etc).
*/
- if (error == EINTR && (tib->tib_canceled == 0 ||
+ if ((error == EINTR || error == ECANCELED) &&
+ (tib->tib_canceled == 0 ||
(tib->tib_cantcancel & CANCEL_DISABLED))) {
_spinlock(&mutex->lock);
continue;