[Midnightbsd-cvs] src [9368] trunk: EINTR in POSIX sem_*.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Mar 4 14:53:28 EST 2017


Revision: 9368
          http://svnweb.midnightbsd.org/src/?rev=9368
Author:   laffer1
Date:     2017-03-04 14:53:27 -0500 (Sat, 04 Mar 2017)
Log Message:
-----------
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.

Obtained from: FreeBSD

Modified Paths:
--------------
    trunk/lib/libc/gen/sem_wait.3
    trunk/sys/kern/kern_umtx.c

Modified: trunk/lib/libc/gen/sem_wait.3
===================================================================
--- trunk/lib/libc/gen/sem_wait.3	2017-03-04 19:52:36 UTC (rev 9367)
+++ trunk/lib/libc/gen/sem_wait.3	2017-03-04 19:53:27 UTC (rev 9368)
@@ -27,7 +27,7 @@
 .\"
 .\" $MidnightBSD$
 .\"
-.Dd February 15, 2000
+.Dd April 16, 2013
 .Dt SEM_WAIT 3
 .Os
 .Sh NAME
@@ -75,6 +75,14 @@
 .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: trunk/sys/kern/kern_umtx.c
===================================================================
--- trunk/sys/kern/kern_umtx.c	2017-03-04 19:52:36 UTC (rev 9367)
+++ trunk/sys/kern/kern_umtx.c	2017-03-04 19:53:27 UTC (rev 9368)
@@ -2970,7 +2970,8 @@
 		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);



More information about the Midnightbsd-cvs mailing list