Date: Wed, 29 Aug 2012 16:37:48 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r239860 - in stable/8/sys: kern sys Message-ID: <201208291637.q7TGbmZh079009@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Wed Aug 29 16:37:48 2012 New Revision: 239860 URL: http://svn.freebsd.org/changeset/base/239860 Log: MFC r238614: Implement F_DUPFD_CLOEXEC command for fcntl(2), specified by SUSv4. MFC r238627: Remove line which was accidentally kept in r238614. PR: standards/169962 Modified: stable/8/sys/kern/kern_descrip.c stable/8/sys/sys/fcntl.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/kern/ (props changed) stable/8/sys/sys/ (props changed) Modified: stable/8/sys/kern/kern_descrip.c ============================================================================== --- stable/8/sys/kern/kern_descrip.c Wed Aug 29 16:26:41 2012 (r239859) +++ stable/8/sys/kern/kern_descrip.c Wed Aug 29 16:37:48 2012 (r239860) @@ -100,6 +100,7 @@ static uma_zone_t file_zone; /* Flags for do_dup() */ #define DUP_FIXED 0x1 /* Force fixed allocation */ #define DUP_FCNTL 0x2 /* fcntl()-style errors */ +#define DUP_CLOEXEC 0x4 /* Atomically set FD_CLOEXEC. */ static int do_dup(struct thread *td, int flags, int old, int new, register_t *retval); @@ -441,6 +442,12 @@ kern_fcntl(struct thread *td, int fd, in error = do_dup(td, DUP_FCNTL, fd, tmp, td->td_retval); break; + case F_DUPFD_CLOEXEC: + tmp = arg; + error = do_dup(td, DUP_FCNTL | DUP_CLOEXEC, fd, tmp, + td->td_retval); + break; + case F_DUP2FD: tmp = arg; error = do_dup(td, DUP_FIXED, fd, tmp, td->td_retval); @@ -848,7 +855,10 @@ do_dup(struct thread *td, int flags, int * Duplicate the source descriptor */ fdp->fd_ofiles[new] = fp; - fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] &~ UF_EXCLOSE; + if ((flags & DUP_CLOEXEC) != 0) + fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] | UF_EXCLOSE; + else + fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] & ~UF_EXCLOSE; if (new > fdp->fd_lastfile) fdp->fd_lastfile = new; *retval = new; Modified: stable/8/sys/sys/fcntl.h ============================================================================== --- stable/8/sys/sys/fcntl.h Wed Aug 29 16:26:41 2012 (r239859) +++ stable/8/sys/sys/fcntl.h Wed Aug 29 16:37:48 2012 (r239860) @@ -225,6 +225,9 @@ typedef __pid_t pid_t; #define F_SETLK_REMOTE 14 /* debugging support for remote locks */ #define F_READAHEAD 15 /* read ahead */ #define F_RDAHEAD 16 /* Darwin compatible read ahead */ +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 +#define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */ +#endif /* file descriptor flags (F_GETFD, F_SETFD) */ #define FD_CLOEXEC 1 /* close-on-exec flag */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201208291637.q7TGbmZh079009>