misc/70798: Compatibility: Sun/Solaris has an fcntl() F_DUP2FD.
FreeBSD could support it too.
Jukka Ukkonen
jau at iki.fi
Sat Aug 21 12:20:24 PDT 2004
>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 at 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:
More information about the freebsd-bugs
mailing list