kern/105346: fcntl(): prevent useless locking with F_DUPFD

Ed Schouten ed at fxq.nl
Thu Nov 9 22:11:29 UTC 2006


>Number:         105346
>Category:       kern
>Synopsis:       fcntl(): prevent useless locking with F_DUPFD
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 09 22:10:20 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Ed Schouten
>Release:        FreeBSD 6.2-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD palm.hoeg.nl 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #0: Fri Oct 6 14:06:07 CEST 2006 root at palm.hoeg.nl:/usr/obj/usr/src/sys/PALM i386
>Description:
The system calls dup() and dup2() allow you to duplicate file
descriptors. The fcntl(..., F_DUPFD, ...) function allows you to do
something similar as dup(). The only difference is the errno variable
that is returned when the given offset is too high.

The FreeBSD kernel implements all dup() related functionality through
the do_dup() function. The problem is that the kern_fcntl() function
almost performs the same tests as the do_dup() call, causing some
duplicate code and worst of all: more locking.
>How-To-Repeat:
n/a
>Fix:
The patch located at http://g-rave.nl/junk/freebsd-kern_descrip.diff
makes kern_fcntl() immediately call do_dup() when the request is
F_DUPFD, causing the FILEDESC_LOCK and PROC_LOCK to be contested only
once in do_dup().

It also changes the errno when the offset is too high to EINVAL instead
of EMFILE. The dup() and dup2() functions will set it back to EMFILE to
remain POSIX compliant.
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list