summaryrefslogtreecommitdiff
path: root/sys/kern/vfs_syscalls.c
diff options
context:
space:
mode:
authorMatthew Dempsky <matthew@cvs.openbsd.org>2012-05-21 16:41:04 +0000
committerMatthew Dempsky <matthew@cvs.openbsd.org>2012-05-21 16:41:04 +0000
commit3c1fa8e419a5e898b32c4ef37779f8fd20ee0d03 (patch)
tree0f65ca68802374f5f70eecd3e784908032342add /sys/kern/vfs_syscalls.c
parent1d6a8efae8419f4d0742c0677fc7181dec6e243a (diff)
Cleanup O_CLOEXEC handling and make sure UF_EXCLOSE is set correctly
when opening /dev/fd/* (i.e., UF_EXCLOSE is now set iff O_CLOEXEC is set, rather than copying UF_EXCLOSE from the file descriptor being dup'd). Also, add support for O_CLOEXEC and O_DIRECTORY to fhopen(). ok krw, guenther; feedback from millert; testing and bug finding by krw
Diffstat (limited to 'sys/kern/vfs_syscalls.c')
-rw-r--r--sys/kern/vfs_syscalls.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 6ac0211eb36..adfd1684156 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.183 2012/05/14 02:41:13 guenther Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.184 2012/05/21 16:41:03 matthew Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -859,8 +859,10 @@ doopenat(struct proc *p, int fd, const char *path, int oflags, mode_t mode,
if ((error = falloc(p, &fp, &indx)) != 0)
goto out;
-
flags = FFLAGS(oflags);
+ if (flags & O_CLOEXEC)
+ fdp->fd_ofileflags[indx] |= UF_EXCLOSE;
+
cmode = ((mode &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT;
NDINITAT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, fd, path, p);
p->p_dupfd = -1; /* XXX check for fdopen */
@@ -932,8 +934,6 @@ doopenat(struct proc *p, int fd, const char *path, int oflags, mode_t mode,
}
}
VOP_UNLOCK(vp, 0, p);
- if (flags & O_CLOEXEC)
- fdp->fd_ofileflags[indx] |= UF_EXCLOSE;
*retval = indx;
FILE_SET_MATURE(fp, p);
out:
@@ -1019,6 +1019,8 @@ sys_fhopen(struct proc *p, void *v, register_t *retval)
fp = NULL;
goto bad;
}
+ if (flags & O_CLOEXEC)
+ fdp->fd_ofileflags[indx] |= UF_EXCLOSE;
if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0)
goto bad;
@@ -1039,6 +1041,10 @@ sys_fhopen(struct proc *p, void *v, register_t *retval)
error = EOPNOTSUPP;
goto bad;
}
+ if ((flags & O_DIRECTORY) && vp->v_type != VDIR) {
+ error = ENOTDIR;
+ goto bad;
+ }
if (flags & FREAD) {
if ((error = VOP_ACCESS(vp, VREAD, cred, p)) != 0)
goto bad;