diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2013-04-19 10:16:00 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2013-04-19 10:16:00 +0000 |
commit | 1e367efa8bd61a973bd4702de2836af8f896cb23 (patch) | |
tree | ec1facf95300fccb6ce1c320d05d8857cf846d56 /sys/kern/kern_umtx.c | |
parent | 7904f516555ab1f7c8401ded6842867556029c96 (diff) | |
download | src-1e367efa8bd61a973bd4702de2836af8f896cb23.tar.gz src-1e367efa8bd61a973bd4702de2836af8f896cb23.zip |
sem: Restart the POSIX sem_* calls after signals with SA_RESTART set.
Programs often do not expect an [EINTR] return from sem_wait() and POSIX
only allows it if the signal was installed without SA_RESTART. The timeout
in sem_timedwait() is absolute so it can be restarted normally.
The umtx call can be invoked with a relative timeout and in that case
[ERESTART] must be changed to [EINTR]. However, libc does not do this.
The old POSIX semaphore implementation did this correctly (before r249566),
unlike the new umtx one.
It may be desirable to avoid [EINTR] completely, which matches the pthread
functions and is explicitly permitted by POSIX. However, the kernel must
return [EINTR] at least for signals with SA_RESTART clear, otherwise pthread
cancellation will not abort a semaphore wait. In this commit, only restore
the 8.x behaviour which is also permitted by POSIX.
Discussed with: jhb
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=249644
Diffstat (limited to 'sys/kern/kern_umtx.c')
-rw-r--r-- | sys/kern/kern_umtx.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index 6026b8080dbf..74d6d1ebb1f9 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -2980,7 +2980,9 @@ do_sem_wait(struct thread *td, struct _usem *sem, struct _umtx_time *timeout) error = 0; else { umtxq_remove(uq); - if (error == ERESTART) + /* A relative timeout cannot be restarted. */ + if (error == ERESTART && timeout != NULL && + (timeout->_flags & UMTX_ABSTIME) == 0) error = EINTR; } umtxq_unlock(&uq->uq_key); |