closefrom(2)

Joerg Sonnenberger joerg at britannica.bec.de
Mon Apr 4 13:57:00 PDT 2005


Hi all,
attached patch implements (somewhat naively) closefrom.
It was on my list for too long.

Joerg
Index: kern/init_sysent.c
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/kern/init_sysent.c,v
retrieving revision 1.27
diff -u -r1.27 init_sysent.c
--- kern/init_sysent.c	21 Mar 2005 16:47:49 -0000	1.27
+++ kern/init_sysent.c	4 Apr 2005 20:09:18 -0000
@@ -2,7 +2,7 @@
  * System call switch table.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $DragonFly: src/sys/kern/init_sysent.c,v 1.27 2005/03/21 16:47:49 joerg Exp $
+ * $DragonFly$
  * created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
  */
 
@@ -496,4 +496,5 @@
 	{ AS(jail_attach_args), (sy_call_t *)jail_attach },	/* 471 = jail_attach */
 	{ AS(sys_set_tls_area_args), (sy_call_t *)sys_set_tls_area },	/* 472 = sys_set_tls_area */
 	{ AS(sys_get_tls_area_args), (sy_call_t *)sys_get_tls_area },	/* 473 = sys_get_tls_area */
+	{ AS(closefrom_args), (sy_call_t *)closefrom },	/* 474 = closefrom */
 };
Index: kern/kern_descrip.c
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/kern/kern_descrip.c,v
retrieving revision 1.39
diff -u -r1.39 kern_descrip.c
--- kern/kern_descrip.c	2 Feb 2005 20:36:09 -0000	1.39
+++ kern/kern_descrip.c	4 Apr 2005 20:33:33 -0000
@@ -609,9 +609,49 @@
 }
 
 /*
+ * Close many file descriptors.
+ */
+/* ARGSUSED */
+
+int
+closefrom(struct closefrom_args *uap)
+{
+	return(kern_closefrom(uap->fd));
+}
+
+int
+kern_closefrom(int fd)
+{
+	struct thread *td = curthread;
+	struct proc *p = td->td_proc;
+	struct filedesc *fdp;
+	int currfd, error;
+
+	KKASSERT(p);
+	fdp = p->p_fd;
+
+	if (fd < 0) /* XXX error? */
+		return(EINVAL);
+	if (fd > fdp->fd_lastfile)
+		return(EBADF);
+	while ((currfd = fdp->fd_lastfile) >= fd) {
+		if (fdp->fd_ofiles[currfd] != NULL) {
+			error = kern_close(currfd);
+			if (error != 0 && error != EBADF)
+				return(error);
+		} else {
+			KASSERT((currfd == 0), ("fdp->fd_lastfile invalid"));
+			break;
+		}
+	}
+	return(0);
+}
+
+/*
  * Close a file descriptor.
  */
 /* ARGSUSED */
+
 int
 close(struct close_args *uap)
 {
Index: kern/syscalls.c
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/kern/syscalls.c,v
retrieving revision 1.26
diff -u -r1.26 syscalls.c
--- kern/syscalls.c	21 Mar 2005 16:47:49 -0000	1.26
+++ kern/syscalls.c	4 Apr 2005 20:09:18 -0000
@@ -2,7 +2,7 @@
  * System call names.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $DragonFly: src/sys/kern/syscalls.c,v 1.26 2005/03/21 16:47:49 joerg Exp $
+ * $DragonFly$
  * created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
  */
 
@@ -481,4 +481,5 @@
 	"jail_attach",			/* 471 = jail_attach */
 	"sys_set_tls_area",			/* 472 = sys_set_tls_area */
 	"sys_get_tls_area",			/* 473 = sys_get_tls_area */
+	"closefrom",			/* 474 = closefrom */
 };
Index: kern/syscalls.master
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/kern/syscalls.master,v
retrieving revision 1.21
diff -u -r1.21 syscalls.master
--- kern/syscalls.master	21 Mar 2005 16:45:08 -0000	1.21
+++ kern/syscalls.master	4 Apr 2005 20:09:18 -0000
@@ -638,4 +638,5 @@
 471	STD	BSD	{ int jail_attach(int jid); }
 472	STD	BSD	{ int sys_set_tls_area(int which, struct tls_info *info, size_t infosize); }
 473	STD	BSD	{ int sys_get_tls_area(int which, struct tls_info *info, size_t infosize); }
+474	STD	BSD	{ int closefrom(int fd); }
 
Index: sys/kern_syscall.h
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/sys/kern_syscall.h,v
retrieving revision 1.26
diff -u -r1.26 kern_syscall.h
--- sys/kern_syscall.h	31 Jan 2005 17:20:48 -0000	1.26
+++ sys/kern_syscall.h	4 Apr 2005 20:09:18 -0000
@@ -141,6 +141,7 @@
 int kern_mknod(struct nlookupdata *nd, int mode, int dev);
 int kern_open(struct nlookupdata *nd, int flags, int mode, int *res);
 int kern_close(int fd);
+int kern_closefrom(int fd);
 int kern_readlink(struct nlookupdata *nd, char *buf, int count, int *res);
 int kern_rename(struct nlookupdata *fromnd, struct nlookupdata *tond);
 int kern_rmdir(struct nlookupdata *nd);
Index: sys/syscall-args
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/sys/syscall-args,v
retrieving revision 1.11
diff -u -r1.11 syscall-args
--- sys/syscall-args	21 Mar 2005 16:47:49 -0000	1.11
+++ sys/syscall-args	4 Apr 2005 20:09:18 -0000
@@ -1,6 +1,6 @@
 # System call argument table.
 # DO NOT EDIT-- this file is automatically generated.
-# $DragonFly: src/sys/sys/syscall-args,v 1.11 2005/03/21 16:47:49 joerg Exp $
+# $DragonFly$
 
 # Created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
 
@@ -263,3 +263,4 @@
 int	jail_attach	jail_attach	jail_attach_args	int	jid
 int	sys_set_tls_area	sys_set_tls_area	sys_set_tls_area_args	int	which	struct tls_info *	info	size_t	infosize
 int	sys_get_tls_area	sys_get_tls_area	sys_get_tls_area_args	int	which	struct tls_info *	info	size_t	infosize
+int	closefrom	closefrom	closefrom_args	int	fd
Index: sys/syscall-hide.h
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/sys/syscall-hide.h,v
retrieving revision 1.28
diff -u -r1.28 syscall-hide.h
--- sys/syscall-hide.h	21 Mar 2005 16:47:49 -0000	1.28
+++ sys/syscall-hide.h	4 Apr 2005 20:09:18 -0000
@@ -2,7 +2,7 @@
  * System call hiders.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $DragonFly: src/sys/sys/syscall-hide.h,v 1.28 2005/03/21 16:47:49 joerg Exp $
+ * $DragonFly$
  * created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
  */
 
@@ -301,3 +301,4 @@
 HIDE_BSD(jail_attach)
 HIDE_BSD(sys_set_tls_area)
 HIDE_BSD(sys_get_tls_area)
+HIDE_BSD(closefrom)
Index: sys/syscall.h
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/sys/syscall.h,v
retrieving revision 1.28
diff -u -r1.28 syscall.h
--- sys/syscall.h	21 Mar 2005 16:47:49 -0000	1.28
+++ sys/syscall.h	4 Apr 2005 20:09:18 -0000
@@ -2,7 +2,7 @@
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $DragonFly: src/sys/sys/syscall.h,v 1.28 2005/03/21 16:47:49 joerg Exp $
+ * $DragonFly$
  * created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
  */
 
@@ -312,4 +312,5 @@
 #define	SYS_jail_attach	471
 #define	SYS_sys_set_tls_area	472
 #define	SYS_sys_get_tls_area	473
-#define	SYS_MAXSYSCALL	474
+#define	SYS_closefrom	474
+#define	SYS_MAXSYSCALL	475
Index: sys/syscall.mk
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/sys/syscall.mk,v
retrieving revision 1.28
diff -u -r1.28 syscall.mk
--- sys/syscall.mk	21 Mar 2005 16:47:49 -0000	1.28
+++ sys/syscall.mk	4 Apr 2005 20:09:19 -0000
@@ -1,6 +1,6 @@
 # DragonFly system call names.
 # DO NOT EDIT-- this file is automatically generated.
-# $DragonFly: src/sys/sys/syscall.mk,v 1.28 2005/03/21 16:47:49 joerg Exp $
+# $DragonFly$
 # created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
 MIASM =  \
 	syscall.o \
@@ -261,4 +261,5 @@
 	umtx_wakeup.o \
 	jail_attach.o \
 	sys_set_tls_area.o \
-	sys_get_tls_area.o
+	sys_get_tls_area.o \
+	closefrom.o
Index: sys/sysproto.h
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/sys/sysproto.h,v
retrieving revision 1.28
diff -u -r1.28 sysproto.h
--- sys/sysproto.h	21 Mar 2005 16:47:49 -0000	1.28
+++ sys/sysproto.h	4 Apr 2005 20:09:19 -0000
@@ -2,7 +2,7 @@
  * System call prototypes.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $DragonFly: src/sys/sys/sysproto.h,v 1.28 2005/03/21 16:47:49 joerg Exp $
+ * $DragonFly$
  * created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
  */
 
@@ -2194,6 +2194,13 @@
 	struct tls_info *	info;	char info_[PAD_(struct tls_info *)];
 	size_t	infosize;	char infosize_[PAD_(size_t)];
 };
+struct	closefrom_args {
+#ifdef _KERNEL
+	struct sysmsg sysmsg;
+#endif
+	union usrmsg usrmsg;
+	int	fd;	char fd_[PAD_(int)];
+};
 
 #ifdef _KERNEL
 
@@ -2454,6 +2461,7 @@
 int	jail_attach (struct jail_attach_args *);
 int	sys_set_tls_area (struct sys_set_tls_area_args *);
 int	sys_get_tls_area (struct sys_get_tls_area_args *);
+int	closefrom (struct closefrom_args *);
 
 #endif /* _KERNEL */
 
Index: sys/sysunion.h
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/sys/sysunion.h,v
retrieving revision 1.25
diff -u -r1.25 sysunion.h
--- sys/sysunion.h	21 Mar 2005 16:47:49 -0000	1.25
+++ sys/sysunion.h	4 Apr 2005 20:09:19 -0000
@@ -2,7 +2,7 @@
  * Union of syscall args for messaging.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $DragonFly: src/sys/sys/sysunion.h,v 1.25 2005/03/21 16:47:49 joerg Exp $
+ * $DragonFly$
  * created from DragonFly: src/sys/kern/syscalls.master,v 1.21 2005/03/21 16:45:08 joerg Exp 
  */
 
@@ -346,4 +346,5 @@
 	struct	jail_attach_args jail_attach;
 	struct	sys_set_tls_area_args sys_set_tls_area;
 	struct	sys_get_tls_area_args sys_get_tls_area;
+	struct	closefrom_args closefrom;
 };




More information about the Submit mailing list