summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/kern/kern_descrip.c11
-rw-r--r--sys/kern/vfs_syscalls.c4
-rw-r--r--sys/sys/fcntl.h4
-rw-r--r--sys/sys/filedesc.h2
4 files changed, 17 insertions, 4 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index a979368..21590d3 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1516,7 +1516,7 @@ fdavail(struct thread *td, int n)
* release the FILEDESC lock.
*/
int
-falloc(struct thread *td, struct file **resultfp, int *resultfd)
+fallocf(struct thread *td, struct file **resultfp, int *resultfd, int flags)
{
struct proc *p = td->td_proc;
struct file *fp;
@@ -1559,6 +1559,8 @@ falloc(struct thread *td, struct file **resultfp, int *resultfd)
return (error);
}
p->p_fd->fd_ofiles[i] = fp;
+ if ((flags & O_CLOEXEC) != 0)
+ p->p_fd->fd_ofileflags[i] |= UF_EXCLOSE;
FILEDESC_XUNLOCK(p->p_fd);
if (resultfp)
*resultfp = fp;
@@ -1567,6 +1569,13 @@ falloc(struct thread *td, struct file **resultfp, int *resultfd)
return (0);
}
+int
+falloc(struct thread *td, struct file **resultfp, int *resultfd)
+{
+
+ return (fallocf(td, resultfp, resultfd, 0));
+}
+
/*
* Build a new filedesc structure from another.
* Copy the current, root, and jail root vnode references.
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 9046d1c..fe66591 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1069,7 +1069,7 @@ kern_openat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
else
flags = FFLAGS(flags);
- error = falloc(td, &nfp, &indx);
+ error = fallocf(td, &nfp, &indx, flags);
if (error)
return (error);
/* An extra reference on `nfp' has been held for us by falloc(). */
@@ -4488,7 +4488,7 @@ fhopen(td, uap)
* end of vn_open code
*/
- if ((error = falloc(td, &nfp, &indx)) != 0) {
+ if ((error = fallocf(td, &nfp, &indx, fmode)) != 0) {
if (fmode & FWRITE)
vp->v_writecount--;
goto bad;
diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
index ef394a3..6f6e348 100644
--- a/sys/sys/fcntl.h
+++ b/sys/sys/fcntl.h
@@ -123,9 +123,11 @@ typedef __pid_t pid_t;
#define FEXEC O_EXEC
#endif
-/* Defined by POSIX 1003.1-2008; BSD default, but reserve for future use. */
#if __POSIX_VISIBLE >= 200809
+/* Defined by POSIX 1003.1-2008; BSD default, but reserve for future use. */
#define O_TTY_INIT 0x00080000 /* Restore default termios attributes */
+
+#define O_CLOEXEC 0x00100000
#endif
/*
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
index dd97d44..c96d6f9 100644
--- a/sys/sys/filedesc.h
+++ b/sys/sys/filedesc.h
@@ -112,6 +112,8 @@ int closef(struct file *fp, struct thread *td);
int dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd,
int mode, int error);
int falloc(struct thread *td, struct file **resultfp, int *resultfd);
+int fallocf(struct thread *td, struct file **resultfp, int *resultfd,
+ int flags);
int fdalloc(struct thread *td, int minfd, int *result);
int fdavail(struct thread *td, int n);
int fdcheckstd(struct thread *td);
OpenPOWER on IntegriCloud