diff options
-rw-r--r-- | lib/libc/sys/Makefile.inc | 73 | ||||
-rw-r--r-- | lib/libc/sys/getdtablecount.2 | 37 | ||||
-rw-r--r-- | sys/kern/kern_descrip.c | 11 | ||||
-rw-r--r-- | sys/kern/syscalls.master | 4 | ||||
-rw-r--r-- | sys/sys/filedesc.h | 3 |
5 files changed, 87 insertions, 41 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 838d63cca31..f598bdb06b8 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.99 2012/03/22 00:44:55 guenther Exp $ +# $OpenBSD: Makefile.inc,v 1.100 2012/04/12 11:07:19 deraadt Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -36,41 +36,40 @@ SRCS+= ftruncate.c lseek.c mquery.c mmap.c ptrace.c semctl.c truncate.c \ SRCS+= stack_protector.c # modules with default implementations on all architectures: -ASM= accept.o access.o acct.o adjfreq.o adjtime.o bind.o chdir.o chflags.o \ - chmod.o \ - chown.o chroot.o clock_gettime.o clock_settime.o clock_getres.o \ - close.o closefrom.o connect.o dup.o dup2.o execve.o fchdir.o \ - fchflags.o fchmod.o fchown.o fcntl.o fhopen.o fhstat.o fhstatfs.o \ - flock.o fpathconf.o fstat.o \ - fstatfs.o fsync.o futimes.o getdirentries.o getegid.o geteuid.o \ - getfh.o getfsstat.o getgid.o getgroups.o getitimer.o \ - getpeername.o \ - getpgid.o \ - getpgrp.o getpid.o getppid.o getpriority.o getresgid.o getresuid.o \ - getrlimit.o getrusage.o getsid.o \ - getsockname.o getsockopt.o gettimeofday.o getuid.o issetugid.o \ - ioctl.o kill.o kevent.o kqueue.o \ - ktrace.o lchown.o lfs_bmapv.o lfs_markv.o lfs_segclean.o lfs_segwait.o \ - link.o listen.o lstat.o madvise.o mincore.o minherit.o mkdir.o \ - mkfifo.o mknod.o mlock.o mlockall.o \ - mount.o mprotect.o msgctl.o msgget.o msgrcv.o msgsnd.o msync.o \ - munlock.o munlockall.o munmap.o nanosleep.o nfssvc.o \ - open.o pathconf.o pipe.o poll.o profil.o quotactl.o \ - read.o readlink.o readv.o reboot.o recvfrom.o recvmsg.o rename.o \ - revoke.o rmdir.o select.o semget.o semop.o sendmsg.o sendto.o \ - setegid.o seteuid.o setgid.o setgroups.o setitimer.o setpgid.o \ - setpriority.o setregid.o setreuid.o setresgid.o setresuid.o \ - setrlimit.o setsid.o setsockopt.o settimeofday.o \ - setuid.o shmat.o shmctl.o shmdt.o shmget.o shutdown.o sigaction.o \ - sigaltstack.o socket.o socketpair.o stat.o statfs.o swapctl.o \ - symlink.o sync.o sysarch.o umask.o unlink.o unmount.o \ - utimes.o wait4.o write.o writev.o nnpfspioctl.o __semctl.o \ - __syscall.o __sysctl.o __getcwd.o sched_yield.o getthrid.o \ - __thrsleep.o __thrwakeup.o __threxit.o __thrsigdivert.o \ - setrtable.o getrtable.o __set_tcb.o __get_tcb.o \ - openat.o fchmodat.o fstatat.o mkdirat.o mkfifoat.o mknodat.o \ - faccessat.o fchownat.o linkat.o readlinkat.o renameat.o symlinkat.o \ - unlinkat.o utimensat.o futimens.o +ASM= __get_tcb.o __getcwd.o __semctl.o __set_tcb.o __syscall.o \ + __sysctl.o __threxit.o __thrsigdivert.o __thrsleep.o \ + __thrwakeup.o accept.o access.o acct.o adjfreq.o adjtime.o \ + bind.o chdir.o chflags.o chmod.o chown.o chroot.o \ + clock_getres.o clock_gettime.o clock_settime.o close.o \ + closefrom.o connect.o dup.o dup2.o execve.o faccessat.o \ + fchdir.o fchflags.o fchmod.o fchmodat.o fchown.o \ + fchownat.o fcntl.o fhopen.o fhstat.o fhstatfs.o \ + flock.o fpathconf.o fstat.o fstatat.o fstatfs.o \ + fsync.o futimens.o futimes.o getdirentries.o getdtablecount.o \ + getegid.o geteuid.o getfh.o getfsstat.o getgid.o \ + getgroups.o getitimer.o getpeername.o getpgid.o getpgrp.o \ + getpid.o getppid.o getpriority.o getresgid.o getresuid.o \ + getrlimit.o getrtable.o getrusage.o getsid.o getsockname.o \ + getsockopt.o getthrid.o gettimeofday.o getuid.o ioctl.o \ + issetugid.o kevent.o kill.o kqueue.o ktrace.o lchown.o \ + lfs_bmapv.o lfs_markv.o lfs_segclean.o lfs_segwait.o \ + link.o linkat.o listen.o lstat.o madvise.o mincore.o \ + minherit.o mkdir.o mkdirat.o mkfifo.o mkfifoat.o \ + mknod.o mknodat.o mlock.o mlockall.o mount.o mprotect.o \ + msgctl.o msgget.o msgrcv.o msgsnd.o msync.o munlock.o \ + munlockall.o munmap.o nanosleep.o nfssvc.o nnpfspioctl.o \ + open.o openat.o pathconf.o pipe.o poll.o profil.o \ + quotactl.o read.o readlink.o readlinkat.o readv.o reboot.o \ + recvfrom.o recvmsg.o rename.o renameat.o revoke.o rmdir.o \ + sched_yield.o select.o semget.o semop.o sendmsg.o sendto.o \ + setegid.o seteuid.o setgid.o setgroups.o setitimer.o \ + setpgid.o setpriority.o setregid.o setresgid.o setresuid.o \ + setreuid.o setrlimit.o setrtable.o setsid.o setsockopt.o \ + settimeofday.o setuid.o shmat.o shmctl.o shmdt.o \ + shmget.o shutdown.o sigaction.o sigaltstack.o socket.o \ + socketpair.o stat.o statfs.o swapctl.o symlink.o \ + symlinkat.o sync.o sysarch.o umask.o unlink.o unlinkat.o \ + unmount.o utimensat.o utimes.o wait4.o write.o writev.o GASM= ${ASM:.o=.go} PASM= ${ASM:.o=.po} @@ -220,7 +219,7 @@ MAN+= accept.2 access.2 acct.2 adjfreq.2 adjtime.2 bind.2 brk.2 chdir.2 \ chflags.2 \ chmod.2 chown.2 chroot.2 clock_gettime.2 close.2 closefrom.2 connect.2 \ dup.2 execve.2 _exit.2 fcntl.2 fhopen.2 \ - flock.2 fork.2 fsync.2 getdirentries.2 \ + flock.2 fork.2 fsync.2 getdirentries.2 getdtablecount.2 \ getfh.2 getfsstat.2 getgid.2 getgroups.2 getitimer.2 getlogin.2 \ getpeername.2 getpgrp.2 getrtable.2 __get_tcb.2 \ getpid.2 getpriority.2 getrlimit.2 getrusage.2 getsid.2 getsockname.2 \ diff --git a/lib/libc/sys/getdtablecount.2 b/lib/libc/sys/getdtablecount.2 new file mode 100644 index 00000000000..eba62e1d83f --- /dev/null +++ b/lib/libc/sys/getdtablecount.2 @@ -0,0 +1,37 @@ +.\" $OpenBSD: getdtablecount.2,v 1.1 2012/04/12 11:07:19 deraadt Exp $ +.\" +.\" Copyright (c) 2012 Theo de Raadt +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: April 12 2012 $ +.Dt GETDTABLECOUNT 2 +.Os +.Sh NAME +.Nm getdtablecount +.Nd get descriptor table count +.Sh SYNOPSIS +.Fd #include <unistd.h> +.Ft int +.Fn getdtablecount void +.Sh DESCRIPTION +Returns the number of file descriptors the process currently has +open. +.Sh SEE ALSO +.Xr getdtablesize 3 , +.Xr getrlimit 2 +.Sh HISTORY +The +.Fn getdtablecount +function call appeared in +.Ox 5.1 . diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index ef18b8bef87..dca42ddc9d7 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.90 2012/04/12 11:01:37 deraadt Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.91 2012/04/12 11:07:20 deraadt Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -155,6 +155,7 @@ fd_used(struct filedesc *fdp, int fd) if (fd > fdp->fd_lastfile) fdp->fd_lastfile = fd; + fdp->fd_openfd++; } static __inline void @@ -175,6 +176,7 @@ fd_unused(struct filedesc *fdp, int fd) #endif if (fd == fdp->fd_lastfile) fdp->fd_lastfile = find_last_set(fdp, fd); + fdp->fd_openfd--; } struct file * @@ -1320,3 +1322,10 @@ sys_closefrom(struct proc *p, void *v, register_t *retval) fdpunlock(fdp); return (0); } + +int +sys_getdtablecount(struct proc *p, void *v, register_t *retval) +{ + *retval = p->p_fd->fd_openfd; + return (0); +} diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index af289aab619..c241438c611 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ -; $OpenBSD: syscalls.master,v 1.120 2012/01/17 02:34:18 guenther Exp $ +; $OpenBSD: syscalls.master,v 1.121 2012/04/12 11:07:19 deraadt Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -72,7 +72,7 @@ 16 STD { int sys_chown(const char *path, uid_t uid, \ gid_t gid); } 17 STD { int sys_obreak(char *nsize); } break -18 OBSOL getfsstat25 +18 STD { int sys_getdtablecount(void); } 19 OBSOL olseek 20 STD NOLOCK { pid_t sys_getpid(void); } 21 STD { int sys_mount(const char *type, const char *path, \ diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 876b3bb6b14..92de6f3040e 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: filedesc.h,v 1.21 2012/02/15 04:26:27 guenther Exp $ */ +/* $OpenBSD: filedesc.h,v 1.22 2012/04/12 11:07:19 deraadt Exp $ */ /* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */ /* @@ -62,6 +62,7 @@ struct filedesc { struct vnode *fd_cdir; /* current directory */ struct vnode *fd_rdir; /* root directory */ int fd_nfiles; /* number of open files allocated */ + int fd_openfd; /* number of files currently open */ u_int *fd_himap; /* each bit points to 32 fds */ u_int *fd_lomap; /* bitmap of free fds */ int fd_lastfile; /* high-water mark of fd_ofiles */ |