diff options
author | Paul Irofti <pirofti@cvs.openbsd.org> | 2018-04-24 16:28:43 +0000 |
---|---|---|
committer | Paul Irofti <pirofti@cvs.openbsd.org> | 2018-04-24 16:28:43 +0000 |
commit | 42d8ef263eb22249f62ae63279fdc3c85980a0e8 (patch) | |
tree | c5ebaa7506e978533dd69ab567615a053fbaef01 /lib/libc | |
parent | 4fb053a8d5cca51b3ebdf34a236bd5320909952f (diff) |
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')
-rw-r--r-- | lib/libc/sys/__thrsleep.2 | 14 | ||||
-rw-r--r-- | lib/libc/thread/rthread_sync.c | 8 |
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/libc/sys/__thrsleep.2 b/lib/libc/sys/__thrsleep.2 index 2566d043fab..28dc4483688 100644 --- a/lib/libc/sys/__thrsleep.2 +++ b/lib/libc/sys/__thrsleep.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: __thrsleep.2,v 1.6 2016/09/03 17:02:22 akfaew Exp $ +.\" $OpenBSD: __thrsleep.2,v 1.7 2018/04/24 16:28:42 pirofti Exp $ .\" .\" Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 3 2016 $ +.Dd $Mdocdate: April 24 2018 $ .Dt __THRSLEEP 2 .Os .Sh NAME @@ -148,12 +148,19 @@ arguments was reached. A signal arrived or the .Fa abort argument pointed to a non-zero value. +.It Bq Er ECANCELED +A signal arrived and +.Fa SA_RESTART +was set. .It Bq Er EINVAL The .Fa clock_id argument is not a valid .Xr clock_gettime 2 -clock id. +clock id +or +.Fa abstime +specified a nanosecond value less than zero or greater than 1000 million. .El .Pp .Fn __thrwakeup @@ -167,6 +174,7 @@ with the same were found. .El .Sh SEE ALSO +.Xr sigaction 2 , .Xr pthread_cond_wait 3 , .Xr pthread_mutex_lock 3 , .Xr tsleep 9 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; |