kern_descrip.c (223785) | kern_descrip.c (223825) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 223785 2011-07-05 13:45:10Z jonathan $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 223825 2011-07-06 20:06:44Z trasz $"); |
39 40#include "opt_capsicum.h" 41#include "opt_compat.h" 42#include "opt_ddb.h" 43#include "opt_ktrace.h" 44 45#include <sys/param.h> 46#include <sys/systm.h> --- 769 unchanged lines hidden (view full) --- 816 /* 817 * The resource limits are here instead of e.g. fdalloc(), 818 * because the file descriptor table may be shared between 819 * processes, so we can't really use racct_add()/racct_sub(). 820 * Instead of counting the number of actually allocated 821 * descriptors, just put the limit on the size of the file 822 * descriptor table. 823 */ | 39 40#include "opt_capsicum.h" 41#include "opt_compat.h" 42#include "opt_ddb.h" 43#include "opt_ktrace.h" 44 45#include <sys/param.h> 46#include <sys/systm.h> --- 769 unchanged lines hidden (view full) --- 816 /* 817 * The resource limits are here instead of e.g. fdalloc(), 818 * because the file descriptor table may be shared between 819 * processes, so we can't really use racct_add()/racct_sub(). 820 * Instead of counting the number of actually allocated 821 * descriptors, just put the limit on the size of the file 822 * descriptor table. 823 */ |
824#ifdef RACCT |
|
824 PROC_LOCK(p); 825 error = racct_set(p, RACCT_NOFILE, new + 1); 826 PROC_UNLOCK(p); 827 if (error != 0) { 828 FILEDESC_XUNLOCK(fdp); 829 fdrop(fp, td); 830 return (EMFILE); 831 } | 825 PROC_LOCK(p); 826 error = racct_set(p, RACCT_NOFILE, new + 1); 827 PROC_UNLOCK(p); 828 if (error != 0) { 829 FILEDESC_XUNLOCK(fdp); 830 fdrop(fp, td); 831 return (EMFILE); 832 } |
833#endif |
|
832 fdgrowtable(fdp, new + 1); 833 } 834 if (fdp->fd_ofiles[new] == NULL) 835 fdused(fdp, new); 836 } else { 837 if ((error = fdalloc(td, new, &new)) != 0) { 838 FILEDESC_XUNLOCK(fdp); 839 fdrop(fp, td); --- 631 unchanged lines hidden (view full) --- 1471/* 1472 * Allocate a file descriptor for the process. 1473 */ 1474int 1475fdalloc(struct thread *td, int minfd, int *result) 1476{ 1477 struct proc *p = td->td_proc; 1478 struct filedesc *fdp = p->p_fd; | 834 fdgrowtable(fdp, new + 1); 835 } 836 if (fdp->fd_ofiles[new] == NULL) 837 fdused(fdp, new); 838 } else { 839 if ((error = fdalloc(td, new, &new)) != 0) { 840 FILEDESC_XUNLOCK(fdp); 841 fdrop(fp, td); --- 631 unchanged lines hidden (view full) --- 1473/* 1474 * Allocate a file descriptor for the process. 1475 */ 1476int 1477fdalloc(struct thread *td, int minfd, int *result) 1478{ 1479 struct proc *p = td->td_proc; 1480 struct filedesc *fdp = p->p_fd; |
1479 int fd = -1, maxfd, error; | 1481 int fd = -1, maxfd; 1482#ifdef RACCT 1483 int error; 1484#endif |
1480 1481 FILEDESC_XLOCK_ASSERT(fdp); 1482 1483 if (fdp->fd_freefile > minfd) 1484 minfd = fdp->fd_freefile; 1485 1486 PROC_LOCK(p); 1487 maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); --- 6 unchanged lines hidden (view full) --- 1494 * may drop the filedesc lock, so we're in a race. 1495 */ 1496 for (;;) { 1497 fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); 1498 if (fd >= maxfd) 1499 return (EMFILE); 1500 if (fd < fdp->fd_nfiles) 1501 break; | 1485 1486 FILEDESC_XLOCK_ASSERT(fdp); 1487 1488 if (fdp->fd_freefile > minfd) 1489 minfd = fdp->fd_freefile; 1490 1491 PROC_LOCK(p); 1492 maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); --- 6 unchanged lines hidden (view full) --- 1499 * may drop the filedesc lock, so we're in a race. 1500 */ 1501 for (;;) { 1502 fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); 1503 if (fd >= maxfd) 1504 return (EMFILE); 1505 if (fd < fdp->fd_nfiles) 1506 break; |
1507#ifdef RACCT |
|
1502 PROC_LOCK(p); 1503 error = racct_set(p, RACCT_NOFILE, min(fdp->fd_nfiles * 2, maxfd)); 1504 PROC_UNLOCK(p); 1505 if (error != 0) 1506 return (EMFILE); | 1508 PROC_LOCK(p); 1509 error = racct_set(p, RACCT_NOFILE, min(fdp->fd_nfiles * 2, maxfd)); 1510 PROC_UNLOCK(p); 1511 if (error != 0) 1512 return (EMFILE); |
1513#endif |
|
1507 fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd)); 1508 } 1509 1510 /* 1511 * Perform some sanity checks, then mark the file descriptor as 1512 * used and return it to the caller. 1513 */ 1514 KASSERT(!fdisused(fdp, fd), --- 299 unchanged lines hidden (view full) --- 1814 struct vnode *cdir, *jdir, *rdir, *vp; 1815 struct flock lf; 1816 1817 /* Certain daemons might not have file descriptors. */ 1818 fdp = td->td_proc->p_fd; 1819 if (fdp == NULL) 1820 return; 1821 | 1514 fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd)); 1515 } 1516 1517 /* 1518 * Perform some sanity checks, then mark the file descriptor as 1519 * used and return it to the caller. 1520 */ 1521 KASSERT(!fdisused(fdp, fd), --- 299 unchanged lines hidden (view full) --- 1821 struct vnode *cdir, *jdir, *rdir, *vp; 1822 struct flock lf; 1823 1824 /* Certain daemons might not have file descriptors. */ 1825 fdp = td->td_proc->p_fd; 1826 if (fdp == NULL) 1827 return; 1828 |
1829#ifdef RACCT |
|
1822 PROC_LOCK(td->td_proc); 1823 racct_set(td->td_proc, RACCT_NOFILE, 0); 1824 PROC_UNLOCK(td->td_proc); | 1830 PROC_LOCK(td->td_proc); 1831 racct_set(td->td_proc, RACCT_NOFILE, 0); 1832 PROC_UNLOCK(td->td_proc); |
1833#endif |
|
1825 1826 /* Check for special need to clear POSIX style locks */ 1827 fdtol = td->td_proc->p_fdtol; 1828 if (fdtol != NULL) { 1829 FILEDESC_XLOCK(fdp); 1830 KASSERT(fdtol->fdl_refcount > 0, 1831 ("filedesc_to_refcount botch: fdl_refcount=%d", 1832 fdtol->fdl_refcount)); --- 1905 unchanged lines hidden --- | 1834 1835 /* Check for special need to clear POSIX style locks */ 1836 fdtol = td->td_proc->p_fdtol; 1837 if (fdtol != NULL) { 1838 FILEDESC_XLOCK(fdp); 1839 KASSERT(fdtol->fdl_refcount > 0, 1840 ("filedesc_to_refcount botch: fdl_refcount=%d", 1841 fdtol->fdl_refcount)); --- 1905 unchanged lines hidden --- |