svn commit: r250569 - in stable/9: lib/libc/gen sys/kern
Jilles Tjoelker
jilles at FreeBSD.org
Wed May 15 04:48:51 UTC 2013
Author: jilles
Date: Sun May 12 16:11:23 2013
New Revision: 250569
URL: http://svnweb.freebsd.org/changeset/base/250569
Log:
MFC r249566,r249644: EINTR in POSIX sem_*.
Document that sem_wait() can fail with [EINTR].
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 old POSIX semaphore implementation did this correctly, unlike the new
umtx one.
Specific to 9-stable: UMTX_ABSTIME does not exist and therefore
sem_timedwait() is erroneously not restarted after a SA_RESTART signal
handler.
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, as far as possible with
the ABI in 9-stable.
Modified:
stable/9/lib/libc/gen/sem_wait.3
stable/9/sys/kern/kern_umtx.c
Directory Properties:
stable/9/lib/libc/ (props changed)
stable/9/sys/ (props changed)
Modified: stable/9/lib/libc/gen/sem_wait.3
==============================================================================
--- stable/9/lib/libc/gen/sem_wait.3 Sun May 12 16:07:23 2013 (r250568)
+++ stable/9/lib/libc/gen/sem_wait.3 Sun May 12 16:11:23 2013 (r250569)
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 15, 2000
+.Dd April 16, 2013
.Dt SEM_WAIT 3
.Os
.Sh NAME
@@ -75,6 +75,14 @@ points to an invalid semaphore.
.El
.Pp
Additionally,
+.Fn sem_wait
+will fail if:
+.Bl -tag -width Er
+.Pp
+.It Bq Er EINTR
+A signal interrupted this function.
+.El
+Additionally,
.Fn sem_trywait
will fail if:
.Bl -tag -width Er
Modified: stable/9/sys/kern/kern_umtx.c
==============================================================================
--- stable/9/sys/kern/kern_umtx.c Sun May 12 16:07:23 2013 (r250568)
+++ stable/9/sys/kern/kern_umtx.c Sun May 12 16:11:23 2013 (r250569)
@@ -2970,7 +2970,8 @@ do_sem_wait(struct thread *td, struct _u
error = 0;
else {
umtxq_remove(uq);
- if (error == ERESTART)
+ /* A relative timeout cannot be restarted. */
+ if (error == ERESTART && timeout != NULL)
error = EINTR;
}
umtxq_unlock(&uq->uq_key);
_______________________________________________
svn-src-all at freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe at freebsd.org"
More information about the svn-src-stable-9
mailing list