Date: Sat, 21 Aug 2004 19:16:45 GMT From: Jukka Ukkonen <jau@iki.fi> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/70798: Compatibility: Sun/Solaris has an fcntl() F_DUP2FD. FreeBSD could support it too. Message-ID: <200408211916.i7LJGjGZ032123@www.freebsd.org> Resent-Message-ID: <200408211920.i7LJKNoJ074512@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200408211916.i7LJGjGZ032123>