[Midnightbsd-cvs] src [7937] trunk/sys: Implement F_DUPFD_CLOEXEC command for fcntl(2), specified by SUSv4.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Sep 14 17:35:29 EDT 2016


Revision: 7937
          http://svnweb.midnightbsd.org/src/?rev=7937
Author:   laffer1
Date:     2016-09-14 17:35:29 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
Implement F_DUPFD_CLOEXEC command for fcntl(2), specified by SUSv4.

Modified Paths:
--------------
    trunk/sys/kern/kern_descrip.c
    trunk/sys/sys/fcntl.h

Modified: trunk/sys/kern/kern_descrip.c
===================================================================
--- trunk/sys/kern/kern_descrip.c	2016-09-14 21:17:23 UTC (rev 7936)
+++ trunk/sys/kern/kern_descrip.c	2016-09-14 21:35:29 UTC (rev 7937)
@@ -113,6 +113,7 @@
 /* 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);
@@ -486,6 +487,12 @@
 		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);
@@ -914,7 +921,10 @@
 	 * 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: trunk/sys/sys/fcntl.h
===================================================================
--- trunk/sys/sys/fcntl.h	2016-09-14 21:17:23 UTC (rev 7936)
+++ trunk/sys/sys/fcntl.h	2016-09-14 21:35:29 UTC (rev 7937)
@@ -225,6 +225,9 @@
 #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 */



More information about the Midnightbsd-cvs mailing list