From owner-svn-src-all@FreeBSD.ORG Sun May 12 16:11:24 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3EB9F15A; Sun, 12 May 2013 16:11:24 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 1680717E; Sun, 12 May 2013 16:11:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4CGBNI2072891; Sun, 12 May 2013 16:11:23 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4CGBNAH072888; Sun, 12 May 2013 16:11:23 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201305121611.r4CGBNAH072888@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 12 May 2013 16:11:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r250569 - in stable/9: lib/libc/gen sys/kern X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 May 2013 16:11:24 -0000 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);