From owner-svn-src-stable@FreeBSD.ORG Tue Jul 14 19:48:33 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E3898106568A; Tue, 14 Jul 2009 19:48:33 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 049608FC0C; Tue, 14 Jul 2009 19:48:32 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6EJmVSI069453; Tue, 14 Jul 2009 19:48:31 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6EJmVs0069443; Tue, 14 Jul 2009 19:48:31 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <200907141948.n6EJmVs0069443@svn.freebsd.org> From: John Baldwin Date: Tue, 14 Jul 2009 19:48:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195694 - in stable/7: include lib/libc lib/libc/sys sys sys/compat/freebsd32 sys/contrib/pf sys/kern sys/sys tools/regression/file tools/regression/file/closefrom tools/regression/file... X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 19:48:35 -0000 Author: jhb Date: Tue Jul 14 19:48:31 2009 New Revision: 195694 URL: http://svn.freebsd.org/changeset/base/195694 Log: MFC: Add a new 'void closefrom(int lowfd)' system call. When called, it closes any open file descriptors >= 'lowfd'. Bump __FreeBSD_version to 702104. Added: stable/7/lib/libc/sys/closefrom.2 - copied unchanged from r194262, head/lib/libc/sys/closefrom.2 stable/7/tools/regression/file/closefrom/ - copied from r194262, head/tools/regression/file/closefrom/ Modified: stable/7/include/ (props changed) stable/7/include/unistd.h stable/7/lib/libc/ (props changed) stable/7/lib/libc/sys/Makefile.inc stable/7/lib/libc/sys/Symbol.map stable/7/lib/libc/sys/close.2 stable/7/sys/ (props changed) stable/7/sys/compat/freebsd32/syscalls.master stable/7/sys/contrib/pf/ (props changed) stable/7/sys/kern/kern_descrip.c stable/7/sys/kern/syscalls.master stable/7/sys/sys/param.h stable/7/tools/regression/file/ (props changed) stable/7/tools/regression/file/flock/ (props changed) Modified: stable/7/include/unistd.h ============================================================================== --- stable/7/include/unistd.h Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/include/unistd.h Tue Jul 14 19:48:31 2009 (r195694) @@ -326,6 +326,7 @@ unsigned int alarm(unsigned int); int chdir(const char *); int chown(const char *, uid_t, gid_t); int close(int); +void closefrom(int); int dup(int); int dup2(int, int); int eaccess(const char *, int); Modified: stable/7/lib/libc/sys/Makefile.inc ============================================================================== --- stable/7/lib/libc/sys/Makefile.inc Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/lib/libc/sys/Makefile.inc Tue Jul 14 19:48:31 2009 (r195694) @@ -63,7 +63,7 @@ MAN+= _exit.2 abort2.2 accept.2 access.2 aio_cancel.2 aio_error.2 aio_read.2 aio_return.2 \ aio_suspend.2 aio_waitcomplete.2 aio_write.2 \ bind.2 brk.2 chdir.2 chflags.2 \ - chmod.2 chown.2 chroot.2 clock_gettime.2 close.2 \ + chmod.2 chown.2 chroot.2 clock_gettime.2 close.2 closefrom.2 \ connect.2 cpuset.2 cpuset_getaffinity.2 dup.2 execve.2 \ extattr_get_file.2 fcntl.2 fhopen.2 flock.2 fork.2 fsync.2 \ getdirentries.2 getdtablesize.2 \ Modified: stable/7/lib/libc/sys/Symbol.map ============================================================================== --- stable/7/lib/libc/sys/Symbol.map Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/lib/libc/sys/Symbol.map Tue Jul 14 19:48:31 2009 (r195694) @@ -337,6 +337,7 @@ FBSD_1.0 { }; FBSD_1.1 { + closefrom; cpuset; cpuset_getid; cpuset_setid; @@ -458,6 +459,8 @@ FBSDprivate_1.0 { __sys_clock_settime; _close; __sys_close; + _closefrom; + __sys_closefrom; _connect; __sys_connect; _cpuset; Modified: stable/7/lib/libc/sys/close.2 ============================================================================== --- stable/7/lib/libc/sys/close.2 Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/lib/libc/sys/close.2 Tue Jul 14 19:48:31 2009 (r195694) @@ -120,6 +120,7 @@ before all pending data was delivered. .El .Sh SEE ALSO .Xr accept 2 , +.Xr closefrom 2 , .Xr execve 2 , .Xr fcntl 2 , .Xr flock 2 , Copied: stable/7/lib/libc/sys/closefrom.2 (from r194262, head/lib/libc/sys/closefrom.2) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/7/lib/libc/sys/closefrom.2 Tue Jul 14 19:48:31 2009 (r195694, copy of r194262, head/lib/libc/sys/closefrom.2) @@ -0,0 +1,53 @@ +.\" Copyright (c) 2009 Advanced Computing Technologies LLC +.\" Written by: John H. Baldwin +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd June 12, 2009 +.Dt CLOSEFROM 2 +.Os +.Sh NAME +.Nm closefrom +.Nd delete open file descriptors +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft void +.Fn closefrom "int lowfd" +.Sh DESCRIPTION +The +.Fn closefrom +system call deletes all open file descriptors greater than or equal to +.Fa lowfd +from the per-process object reference table. +Any errors encountered while closing file descriptors are ignored. +.Sh SEE ALSO +.Xr close 2 +.Sh HISTORY +The +.Fn closefrom +function first appeared in +.Fx 8.0 . Modified: stable/7/sys/compat/freebsd32/syscalls.master ============================================================================== --- stable/7/sys/compat/freebsd32/syscalls.master Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/sys/compat/freebsd32/syscalls.master Tue Jul 14 19:48:31 2009 (r195694) @@ -854,3 +854,24 @@ uint32_t idlo, uint32_t idhi, \ size_t cpusetsize, \ const cpuset_t *mask); } +489 AUE_NULL UNIMPL faccessat +490 AUE_NULL UNIMPL fchmodat +491 AUE_NULL UNIMPL fchownat +492 AUE_NULL UNIMPL freebsd32_fexecve +493 AUE_NULL UNIMPL freebsd32_fstatat +494 AUE_NULL UNIMPL freebsd32_futimesat +495 AUE_NULL UNIMPL linkat +496 AUE_NULL UNIMPL mkdirat +497 AUE_NULL UNIMPL mkfifoat +498 AUE_NULL UNIMPL mknodat +499 AUE_NULL UNIMPL openat +500 AUE_NULL UNIMPL readlinkat +501 AUE_NULL UNIMPL renameat +502 AUE_NULL UNIMPL symlinkat +503 AUE_NULL UNIMPL unlinkat +504 AUE_NULL UNIMPL posix_openpt +505 AUE_NULL UNIMPL gssd_syscall +506 AUE_NULL UNIMPL freebsd32_jail_get +507 AUE_NULL UNIMPL freebsd32_jail_set +508 AUE_NULL UNIMPL jail_remove +509 AUE_CLOSEFROM NOPROTO { int closefrom(int lowfd); } Modified: stable/7/sys/kern/kern_descrip.c ============================================================================== --- stable/7/sys/kern/kern_descrip.c Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/sys/kern/kern_descrip.c Tue Jul 14 19:48:31 2009 (r195694) @@ -1136,6 +1136,42 @@ kern_close(td, fd) return (error); } +/* + * Close open file descriptors. + */ +#ifndef _SYS_SYSPROTO_H_ +struct closefrom_args { + int lowfd; +}; +#endif +/* ARGSUSED */ +int +closefrom(struct thread *td, struct closefrom_args *uap) +{ + struct filedesc *fdp; + int fd; + + fdp = td->td_proc->p_fd; + AUDIT_ARG(fd, uap->lowfd); + + /* + * Treat negative starting file descriptor values identical to + * closefrom(0) which closes all files. + */ + if (uap->lowfd < 0) + uap->lowfd = 0; + FILEDESC_SLOCK(fdp); + for (fd = uap->lowfd; fd < fdp->fd_nfiles; fd++) { + if (fdp->fd_ofiles[fd] != NULL) { + FILEDESC_SUNLOCK(fdp); + (void)kern_close(td, fd); + FILEDESC_SLOCK(fdp); + } + } + FILEDESC_SUNLOCK(fdp); + return (0); +} + #if defined(COMPAT_43) /* * Return status information about a file descriptor. Modified: stable/7/sys/kern/syscalls.master ============================================================================== --- stable/7/sys/kern/syscalls.master Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/sys/kern/syscalls.master Tue Jul 14 19:48:31 2009 (r195694) @@ -870,6 +870,26 @@ 488 AUE_NULL STD { int cpuset_setaffinity(cpulevel_t level, \ cpuwhich_t which, id_t id, size_t cpusetsize, \ const cpuset_t *mask); } - +489 AUE_NULL UNIMPL faccessat +490 AUE_NULL UNIMPL fchmodat +491 AUE_NULL UNIMPL fchownat +492 AUE_NULL UNIMPL fexecve +493 AUE_NULL UNIMPL fstatat +494 AUE_NULL UNIMPL futimesat +495 AUE_NULL UNIMPL linkat +496 AUE_NULL UNIMPL mkdirat +497 AUE_NULL UNIMPL mkfifoat +498 AUE_NULL UNIMPL mknodat +499 AUE_NULL UNIMPL openat +500 AUE_NULL UNIMPL readlinkat +501 AUE_NULL UNIMPL renameat +502 AUE_NULL UNIMPL symlinkat +503 AUE_NULL UNIMPL unlinkat +504 AUE_NULL UNIMPL posix_openpt +505 AUE_NULL UNIMPL gssd_syscall +506 AUE_NULL UNIMPL jail_get +507 AUE_NULL UNIMPL jail_set +508 AUE_NULL UNIMPL jail_remove +509 AUE_CLOSEFROM STD { int closefrom(int lowfd); } ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master Modified: stable/7/sys/sys/param.h ============================================================================== --- stable/7/sys/sys/param.h Tue Jul 14 19:45:36 2009 (r195693) +++ stable/7/sys/sys/param.h Tue Jul 14 19:48:31 2009 (r195694) @@ -57,7 +57,7 @@ * is created, otherwise 1. */ #undef __FreeBSD_version -#define __FreeBSD_version 702103 /* Master, propagated to newvers */ +#define __FreeBSD_version 702104 /* Master, propagated to newvers */ #ifndef LOCORE #include