From owner-freebsd-bugs@FreeBSD.ORG Sat Aug 21 19:20:24 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 534AA16A4D4 for ; Sat, 21 Aug 2004 19:20:24 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1E93043D3F for ; Sat, 21 Aug 2004 19:20:24 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i7LJKN0n074513 for ; Sat, 21 Aug 2004 19:20:23 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i7LJKNoJ074512; Sat, 21 Aug 2004 19:20:23 GMT (envelope-from gnats) Resent-Date: Sat, 21 Aug 2004 19:20:23 GMT Resent-Message-Id: <200408211920.i7LJKNoJ074512@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jukka Ukkonen Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B494416A4CE for ; Sat, 21 Aug 2004 19:16:45 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id AA12143D3F for ; Sat, 21 Aug 2004 19:16:45 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i7LJGj4s032124 for ; Sat, 21 Aug 2004 19:16:45 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.11/8.12.11/Submit) id i7LJGjGZ032123; Sat, 21 Aug 2004 19:16:45 GMT (envelope-from nobody) Message-Id: <200408211916.i7LJGjGZ032123@www.freebsd.org> Date: Sat, 21 Aug 2004 19:16:45 GMT From: Jukka Ukkonen To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: misc/70798: Compatibility: Sun/Solaris has an fcntl() F_DUP2FD. FreeBSD could support it too. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Aug 2004 19:20:24 -0000 >Number: 70798 >Category: misc >Synopsis: Compatibility: Sun/Solaris has an fcntl() F_DUP2FD. FreeBSD could support it too. >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Aug 21 19:20:23 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Jukka Ukkonen >Release: FreeBSD-4.10-STABLE >Organization: Mawit Ltd. >Environment: FreeBSD mjolnir 4.10-STABLE FreeBSD 4.10-STABLE #0: Sat Aug 14 11:58:59 EET DST 2004 jau@mjolnir:/home/src/sys/compile/Mjolnir i386 >Description: This is taken from SunOS/Solaris fcntl() manual page... F_DUP2FD Similar to F_DUPFD, but always returns arg. F_DUP2FD closes arg if it is open and not equal to fildes. F_DUP2FD is equivalent to dup2(fildes, arg). It seems to be very easy to implement this functionality in FreeBSD. 1st step: Add a definition for F_DUP2FD in fcntl.h ... #define F_DUP2FD 10 /* Parallel to dup2() like F_DUPFD is for dup(). */ 2nd step: Add this change to kern_descrip.c ... --- ../kern_descrip.c.old Sat May 17 12:10:06 2003 +++ ../kern_descrip.c Sat May 17 12:10:13 2003 @@ -249,24 +249,35 @@ switch (cmd) { case F_DUPFD: FILEDESC_UNLOCK(fdp); newmin = arg; if (newmin >= p->p_rlimit[RLIMIT_NOFILE].rlim_cur || newmin >= maxfilesperproc) { error = EINVAL; break; } error = do_dup(td, DUP_VARIABLE, fd, newmin, td->td_retval); break; + case F_DUP2FD: + FILEDESC_UNLOCK(fdp); + newmin = arg; + if (newmin >= p->p_rlimit[RLIMIT_NOFILE].rlim_cur || + newmin >= maxfilesperproc) { + error = EINVAL; + break; + } + error = do_dup(td, DUP_FIXED, fd, newmin, td->td_retval); + break; + case F_GETFD: td->td_retval[0] = (*pop & UF_EXCLOSE) ? FD_CLOEXEC : 0; FILEDESC_UNLOCK(fdp); break; case F_SETFD: *pop = (*pop &~ UF_EXCLOSE) | (arg & FD_CLOEXEC ? UF_EXCLOSE : 0); FILEDESC_UNLOCK(fdp); break; case F_GETFL: >How-To-Repeat: Not an actual problem per se unless a lacking portability feature is counted as one. >Fix: See "Full Description" above. >Release-Note: >Audit-Trail: >Unformatted: