changeset 13998:4ba0940c01f8

3665 Implement O_CLOEXEC as an open() flag Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Gordon Ross <gwr@nexenta.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Approved by: Richard Lowe <richlowe@richlowe.net>
author Theo Schlossnagle <jesus@omniti.com>
date Sun, 31 Mar 2013 04:00:15 +0000
parents c5f371428359
children f0c04f0fa2ad
files usr/src/cmd/truss/codes.c usr/src/man/man2/open.2 usr/src/uts/common/sys/fcntl.h usr/src/uts/common/sys/file.h usr/src/uts/common/syscall/open.c
diffstat 5 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/truss/codes.c	Wed Apr 03 14:02:24 2013 -0400
+++ b/usr/src/cmd/truss/codes.c	Sun Mar 31 04:00:15 2013 +0000
@@ -24,6 +24,7 @@
  * Copyright (c) 2012 by Delphix. All rights reserved.
  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
  */
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
@@ -1918,7 +1919,7 @@
 #define	ALL_O_FLAGS \
 	(O_NDELAY|O_APPEND|O_SYNC|O_DSYNC|O_NONBLOCK|O_CREAT|O_TRUNC\
 	|O_EXCL|O_NOCTTY|O_LARGEFILE|O_RSYNC|O_XATTR|O_NOFOLLOW|O_NOLINKS\
-	|FXATTRDIROPEN)
+	|O_CLOEXEC|FXATTRDIROPEN)
 
 const char *
 openarg(private_t *pri, int arg)
@@ -1976,6 +1977,8 @@
 		(void) strlcat(str, "|O_NOFOLLOW", sizeof (pri->code_buf));
 	if (arg & O_NOLINKS)
 		(void) strlcat(str, "|O_NOLINKS", sizeof (pri->code_buf));
+	if (arg & O_CLOEXEC)
+		(void) strlcat(str, "|O_CLOEXEC", sizeof (pri->code_buf));
 	if (arg & FXATTRDIROPEN)
 		(void) strlcat(str, "|FXATTRDIROPEN", sizeof (pri->code_buf));
 
--- a/usr/src/man/man2/open.2	Wed Apr 03 14:02:24 2013 -0400
+++ b/usr/src/man/man2/open.2	Sun Mar 31 04:00:15 2013 +0000
@@ -2,6 +2,7 @@
 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
 .\" Copyright 1989 AT&T
 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
+.\" Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc.  All Rights Reserved.
 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
 .\" http://www.opengroup.org/bookstore/.
 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
@@ -214,6 +215,17 @@
 .sp
 .ne 2
 .na
+\fB\fBO_CLOEXEC\fR\fR
+.ad
+.sp .6
+.RS 4n
+If set, the file descriptor returned will be closed prior to any future
+\fBexec()\fR calls.
+.RE
+
+.sp
+.ne 2
+.na
 \fB\fBO_NONBLOCK\fR or \fBO_NDELAY\fR\fR
 .ad
 .sp .6
--- a/usr/src/uts/common/sys/fcntl.h	Wed Apr 03 14:02:24 2013 -0400
+++ b/usr/src/uts/common/sys/fcntl.h	Sun Mar 31 04:00:15 2013 +0000
@@ -36,6 +36,8 @@
  * contributors.
  */
 
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
 #ifndef	_SYS_FCNTL_H
 #define	_SYS_FCNTL_H
 
@@ -82,6 +84,7 @@
 #define	O_XATTR		0x4000	/* extended attribute */
 #define	O_NOFOLLOW	0x20000	/* don't follow symlinks */
 #define	O_NOLINKS	0x40000	/* don't allow multiple hard links */
+#define	O_CLOEXEC	0x800000	/* set the close-on-exec flag */
 
 /*
  * fcntl(2) requests
--- a/usr/src/uts/common/sys/file.h	Wed Apr 03 14:02:24 2013 -0400
+++ b/usr/src/uts/common/sys/file.h	Sun Mar 31 04:00:15 2013 +0000
@@ -26,6 +26,8 @@
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
 #ifndef _SYS_FILE_H
 #define	_SYS_FILE_H
 
@@ -113,6 +115,8 @@
 #define	FSEARCH		0x200000	/* O_SEARCH = 0x200000 */
 #define	FEXEC		0x400000	/* O_EXEC = 0x400000 */
 
+#define	FCLOEXEC	0x800000	/* O_CLOEXEC = 0x800000 */
+
 #ifdef _KERNEL
 
 /*
--- a/usr/src/uts/common/syscall/open.c	Wed Apr 03 14:02:24 2013 -0400
+++ b/usr/src/uts/common/syscall/open.c	Sun Mar 31 04:00:15 2013 +0000
@@ -27,6 +27,9 @@
 /*	  All Rights Reserved  	*/
 
 /*
+ * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
+ */
+/*
  * Portions of this source code were derived from Berkeley 4.3 BSD
  * under license from the Regents of the University of California.
  */
@@ -226,6 +229,9 @@
 					 * falloc reserved.
 					 */
 					setf(fd, fp);
+					if ((filemode & FCLOEXEC) != 0) {
+						f_setfd(fd, FD_CLOEXEC);
+					}
 					return (fd);
 				} else {
 					/*
@@ -252,6 +258,9 @@
 					fp->f_count++;
 					mutex_exit(&fp->f_tlock);
 					setf(fd, fp);
+					if ((filemode & FCLOEXEC) != 0) {
+						f_setfd(fd, FD_CLOEXEC);
+					}
 					releasef(dupfd);
 				}
 				return (fd);