Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Jan 2013 18:03:43 GMT
From:      Jukka Ukkonen <jau@iki.fi>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/175674: sem_open() should use O_EXLOCK with open() instead of a separate flock() call
Message-ID:  <201301291803.r0TI3h2A088948@red.freebsd.org>
Resent-Message-ID: <201301291810.r0TIA1EZ084283@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         175674
>Category:       kern
>Synopsis:       sem_open() should use O_EXLOCK with open() instead of a separate flock() call
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 29 18:10:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Jukka Ukkonen
>Release:        9.1-STABLE
>Organization:
-----
>Environment:
FreeBSD sleipnir 9.1-STABLE FreeBSD 9.1-STABLE #2 r246056M: Tue Jan 29 07:33:01 EET 2013     root@sleipnir:/usr/obj/usr/src/sys/Sleipnir  amd64
>Description:
sem_open() is calling flock() to set a lock on a newly created file descriptor.
That is pointless. The open() call a few lines before the flock() could, and
in my opinion should, be done with the O_EXLOCK flag set.

>How-To-Repeat:
See "full description" above.
>Fix:
Simply apply the attached patch.
Notice, though, that the patch assumes kern/170369 has been applied first.


Patch attached with submission follows:

--- lib/libc/gen/sem_new.c.flock	2012-11-09 18:50:05.000000000 +0200
+++ lib/libc/gen/sem_new.c	2012-11-09 18:44:59.000000000 +0200
@@ -198,11 +198,13 @@
 		goto error;
 	}
 
-	fd = _open(path, flags|O_RDWR|O_CLOEXEC, mode);
+	fd = _open(path, flags|O_RDWR|O_CLOEXEC|O_EXLOCK, mode);
 	if (fd == -1)
 		goto error;
+#if 0
 	if (flock(fd, LOCK_EX) == -1)
 		goto error;
+#endif
 	if (_fstat(fd, &sb)) {
 		flock(fd, LOCK_UN);
 		goto error;


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301291803.r0TI3h2A088948>