Add F_DUP2FD_CLOEXEC. Apparently Solaris 11 already did this.

Submitted by:	Jukka A. Ukkonen <jau iki fi>
PR:	standards/169962
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2012-07-27 10:41:10 +00:00
parent 9ed9f02b67
commit d8c1da8b90
2 changed files with 11 additions and 0 deletions

View File

@ -491,6 +491,12 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
error = do_dup(td, DUP_FIXED, fd, tmp, td->td_retval);
break;
case F_DUP2FD_CLOEXEC:
tmp = arg;
error = do_dup(td, DUP_FIXED | DUP_CLOEXEC, fd, tmp,
td->td_retval);
break;
case F_GETFD:
FILEDESC_SLOCK(fdp);
if ((fp = fget_locked(fdp, fd)) == NULL) {
@ -849,6 +855,8 @@ do_dup(struct thread *td, int flags, int old, int new,
}
if (flags & DUP_FIXED && old == new) {
*retval = new;
if (flags & DUP_CLOEXEC)
fdp->fd_ofileflags[new] |= UF_EXCLOSE;
FILEDESC_XUNLOCK(fdp);
return (0);
}

View File

@ -232,6 +232,9 @@ typedef __pid_t pid_t;
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
#define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */
#endif
#if __BSD_VISIBLE
#define F_DUP2FD_CLOEXEC 18 /* Like F_DUP2FD, but FD_CLOEXEC is set */
#endif
/* file descriptor flags (F_GETFD, F_SETFD) */
#define FD_CLOEXEC 1 /* close-on-exec flag */