Date: Thu, 9 Nov 2006 23:02:27 +0100 (CET) From: Ed Schouten <ed@fxq.nl> To: FreeBSD-gnats-submit@FreeBSD.org Subject: kern/105346: fcntl(): prevent useless locking with F_DUPFD Message-ID: <20061109220227.7CA461CE94@palm.hoeg.nl> Resent-Message-ID: <200611092210.kA9MAKiY092748@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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@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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061109220227.7CA461CE94>