summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2004-01-12 18:06:52 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2004-01-12 18:06:52 +0000
commit861dfb10bccb89b85bd11a3b64d5b847e874faa0 (patch)
tree05a3e45d1f3a32ff5ae339f50e1f3254646d0211 /sys
parentcb66f6f34a3b631749dd8d2ab1d977832d85f679 (diff)
new syscall closefrom(int fd) closes all fds equal and greater than fd.
ok deraadt@ millert@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_descrip.c24
-rw-r--r--sys/kern/syscalls.master3
2 files changed, 25 insertions, 2 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 5650bd03f38..58887c072d3 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.67 2004/01/06 04:18:18 tedu Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.68 2004/01/12 18:06:51 tedu Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -1295,3 +1295,25 @@ fdcloseexec(p)
if (fdp->fd_ofileflags[fd] & UF_EXCLOSE)
(void) fdrelease(p, fd);
}
+
+int
+sys_closefrom(struct proc *p, void *v, register_t *retval)
+{
+ struct sys_closefrom_args *uap = v;
+ struct filedesc *fdp = p->p_fd;
+ u_int startfd, i;
+
+ startfd = SCARG(uap, fd);
+ fdplock(fdp, p);
+
+ if (startfd > fdp->fd_lastfile) {
+ fdpunlock(fdp);
+ return (EBADF);
+ }
+
+ for (i = startfd; i <= fdp->fd_lastfile; i++)
+ fdrelease(p, i);
+
+ fdpunlock(fdp);
+ return (0);
+}
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index b8bb6d8cd50..6b5d16cc497 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -1,4 +1,4 @@
-; $OpenBSD: syscalls.master,v 1.65 2003/12/31 00:13:24 millert Exp $
+; $OpenBSD: syscalls.master,v 1.66 2004/01/12 18:06:51 tedu Exp $
; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@@ -575,3 +575,4 @@
285 OBSOL sys_omquery
286 STD { void *sys_mquery(void *addr, size_t len, int prot, \
int flags, int fd, long pad, off_t pos); }
+287 STD { int sys_closefrom(int fd); }