From nobody@FreeBSD.org  Sat Aug 21 19:16:45 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B494416A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <jau@iki.fi>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Compatibility: Sun/Solaris has an fcntl() F_DUP2FD. FreeBSD could support it too.
X-Send-Pr-Version: www-2.3

>Number:         70798
>Category:       kern
>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:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 21 19:20:23 GMT 2004
>Closed-Date:    Sat Feb 23 00:04:48 UTC 2008
>Last-Modified:  Sat Feb 23 00:04:48 UTC 2008
>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:
State-Changed-From-To: open->closed 
State-Changed-By: antoine 
State-Changed-When: Sat Feb 23 00:02:50 UTC 2008 
State-Changed-Why:  
Close: superseded by PR 120233 that has an updated patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=70798 
>Unformatted:
