From owner-freebsd-bugs@FreeBSD.ORG Tue Feb 12 00:00:02 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C249FAE7 for ; Tue, 12 Feb 2013 00:00:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id B212980F for ; Tue, 12 Feb 2013 00:00:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r1C001wh027117 for ; Tue, 12 Feb 2013 00:00:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r1C001YO027113; Tue, 12 Feb 2013 00:00:01 GMT (envelope-from gnats) Date: Tue, 12 Feb 2013 00:00:01 GMT Message-Id: <201302120000.r1C001YO027113@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Jilles Tjoelker Subject: Re: kern/175674: sem_open() should use O_EXLOCK with open() instead of a separate flock() call X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2013 00:00:02 -0000 The following reply was made to PR kern/175674; it has been noted by GNATS. From: Jilles Tjoelker To: Giorgos Keramidas Cc: Jukka Ukkonen , freebsd-gnats-submit@FreeBSD.org, davidxu@FreeBSD.org Subject: Re: kern/175674: sem_open() should use O_EXLOCK with open() instead of a separate flock() call Date: Tue, 12 Feb 2013 00:56:42 +0100 On Sun, Feb 03, 2013 at 09:49:55PM +0100, Giorgos Keramidas wrote: > On 2013-02-03 21:20, Jilles Tjoelker wrote: > > For a reason unknown to me, open(2) does not restart but always > > returns [EINTR] when a signal is caught. This is not POSIX-compliant. > > On the other hand, flock(2) is not broken in this way. So this change > > breaks sem_open(3) in the unlikely case that a signal with SA_RESTART > > arrives while it is waiting for the lock. > I see where kern_openat() returns an error when vn_open is interrupted: > 1083 error = vn_open(&nd, &flags, cmode, fp); > 1084 if (error) { > .... > 1109 if (error == ERESTART) > 1110 error = EINTR; > 1111 goto bad; > 1112 } > > The best way to fix this is in kern_openat() in the kernel but this > > might cause compatibility issues. > Not sure if there would be serious compatibility problems if open() > would automatically restart instead of returning EINTR. It definitely > seems a rather intrusive change though. As of r246472, open() is now sufficiently fixed that O_EXLOCK can be used. Although it is not a problem if a different thread than the file creator initializes the semaphore, the change reduces system calls and code size. On another note, the flock(fd, LOCK_UN) calls can go away because they are implicit in the close(fd). -- Jilles Tjoelker