summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorTheo Schlossnagle <jesus@omniti.com>2013-03-31 04:00:15 +0000
committerRichard Lowe <richlowe@richlowe.net>2013-04-03 17:34:56 -0400
commitb075ad5b007248d50e4c2e838b460c9c7cfd9fad (patch)
tree2df4132aec9c5613e95766e82631e06c8b048d1f /usr/src
parent3cc3202e63472d673bcac160bfb86d1865dd9fe7 (diff)
downloadillumos-joyent-b075ad5b007248d50e4c2e838b460c9c7cfd9fad.tar.gz
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>
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/truss/codes.c5
-rw-r--r--usr/src/man/man2/open.212
-rw-r--r--usr/src/uts/common/sys/fcntl.h3
-rw-r--r--usr/src/uts/common/sys/file.h4
-rw-r--r--usr/src/uts/common/syscall/open.c9
5 files changed, 32 insertions, 1 deletions
diff --git a/usr/src/cmd/truss/codes.c b/usr/src/cmd/truss/codes.c
index 4162c8b661..dcab90e5fa 100644
--- a/usr/src/cmd/truss/codes.c
+++ b/usr/src/cmd/truss/codes.c
@@ -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 @@ pathconfname(int code)
#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 @@ openarg(private_t *pri, int arg)
(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));
diff --git a/usr/src/man/man2/open.2 b/usr/src/man/man2/open.2
index 30ae089ca7..522ac12e1e 100644
--- a/usr/src/man/man2/open.2
+++ b/usr/src/man/man2/open.2
@@ -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 @@ sets \fBerrno\fR to \fBEMLINK\fR.
.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
diff --git a/usr/src/uts/common/sys/fcntl.h b/usr/src/uts/common/sys/fcntl.h
index a0c4191b1c..f3ca84fff1 100644
--- a/usr/src/uts/common/sys/fcntl.h
+++ b/usr/src/uts/common/sys/fcntl.h
@@ -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 @@ extern "C" {
#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
diff --git a/usr/src/uts/common/sys/file.h b/usr/src/uts/common/sys/file.h
index f402bc7079..03acc088c2 100644
--- a/usr/src/uts/common/sys/file.h
+++ b/usr/src/uts/common/sys/file.h
@@ -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 @@ typedef struct fpollinfo {
#define FSEARCH 0x200000 /* O_SEARCH = 0x200000 */
#define FEXEC 0x400000 /* O_EXEC = 0x400000 */
+#define FCLOEXEC 0x800000 /* O_CLOEXEC = 0x800000 */
+
#ifdef _KERNEL
/*
diff --git a/usr/src/uts/common/syscall/open.c b/usr/src/uts/common/syscall/open.c
index 6559900158..edb04c824b 100644
--- a/usr/src/uts/common/syscall/open.c
+++ b/usr/src/uts/common/syscall/open.c
@@ -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 @@ noxattr:
* falloc reserved.
*/
setf(fd, fp);
+ if ((filemode & FCLOEXEC) != 0) {
+ f_setfd(fd, FD_CLOEXEC);
+ }
return (fd);
} else {
/*
@@ -252,6 +258,9 @@ noxattr:
fp->f_count++;
mutex_exit(&fp->f_tlock);
setf(fd, fp);
+ if ((filemode & FCLOEXEC) != 0) {
+ f_setfd(fd, FD_CLOEXEC);
+ }
releasef(dupfd);
}
return (fd);