summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2015-02-11 03:03:10 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2015-02-11 03:03:10 +0000
commita97d025f9d557cb2e82b00c37b0d96c54a805a68 (patch)
treed519b13fe30095c21d06350bca185a5525010720 /lib
parentb62d642f586ac0d39a5ae95ec450b3e137b276f2 (diff)
sysctl({CTL_KERN, KERN_FILE, KERN_FILE_BYFILE}) previously required
the extra argument to be zero; instead, make it filter on the file type (DTYPE_*) when non-zero to make claudio's netstat work easier. ok claudio@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/sysctl.36
-rw-r--r--lib/libkvm/kvm_file2.c11
-rw-r--r--lib/libkvm/kvm_getfiles.327
3 files changed, 32 insertions, 12 deletions
diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3
index a691b835fc4..0574aa2f7df 100644
--- a/lib/libc/gen/sysctl.3
+++ b/lib/libc/gen/sysctl.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sysctl.3,v 1.246 2014/12/22 03:33:18 tedu Exp $
+.\" $OpenBSD: sysctl.3,v 1.247 2015/02/11 03:03:09 guenther Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: December 22 2014 $
+.Dd $Mdocdate: February 11 2015 $
.Dt SYSCTL 3
.Os
.Sh NAME
@@ -547,7 +547,7 @@ whose size depends on the current number of selected files in the system.
The third and fourth level names are as follows:
.Bl -column "Third level name" "Fourth level is:" -offset indent
.It Sy "Third level name" Ta Sy "Fourth level is:"
-.It Dv KERN_FILE_BYFILE Ta "Zero"
+.It Dv KERN_FILE_BYFILE Ta "A file type"
.It Dv KERN_FILE_BYPID Ta "A process ID"
.It Dv KERN_FILE_BYUID Ta "A user ID"
.El
diff --git a/lib/libkvm/kvm_file2.c b/lib/libkvm/kvm_file2.c
index 35d26b5ba96..4a6979f7707 100644
--- a/lib/libkvm/kvm_file2.c
+++ b/lib/libkvm/kvm_file2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_file2.c,v 1.41 2015/01/16 16:48:51 deraadt Exp $ */
+/* $OpenBSD: kvm_file2.c,v 1.42 2015/02/11 03:03:08 guenther Exp $ */
/*
* Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -178,11 +178,6 @@ kvm_getfiles(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
deadway:
switch (op) {
case KERN_FILE_BYFILE:
- if (arg != 0) {
- _kvm_err(kd, kd->program,
- "%d: invalid argument", arg);
- return (NULL);
- }
return (kvm_deadfile_byfile(kd, op, arg, esize, cnt));
break;
case KERN_FILE_BYPID:
@@ -239,6 +234,10 @@ kvm_deadfile_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
_kvm_err(kd, kd->program, "can't read kfp");
return (NULL);
}
+ if (file.f_count == 0)
+ continue;
+ if (arg && file.f_type != arg)
+ continue;
if (fill_file(kd, &kf, &file, (u_long)fp, NULL, NULL, 0, 0)
== -1)
return (NULL);
diff --git a/lib/libkvm/kvm_getfiles.3 b/lib/libkvm/kvm_getfiles.3
index f26818fcdc4..b8e0ed58d13 100644
--- a/lib/libkvm/kvm_getfiles.3
+++ b/lib/libkvm/kvm_getfiles.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: kvm_getfiles.3,v 1.16 2013/10/22 16:40:27 guenther Exp $
+.\" $OpenBSD: kvm_getfiles.3,v 1.17 2015/02/11 03:03:08 guenther Exp $
.\" $NetBSD: kvm_getfiles.3,v 1.3 1996/03/18 22:33:23 thorpej Exp $
.\"
.\" Copyright (c) 1992, 1993
@@ -34,7 +34,7 @@
.\"
.\" @(#)kvm_getfiles.3 8.2 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: October 22 2013 $
+.Dd $Mdocdate: February 11 2015 $
.Dt KVM_GETFILES 3
.Os
.Sh NAME
@@ -62,7 +62,9 @@ describes the filtering predicate as follows:
.Pp
.Bl -tag -width 20n -offset indent -compact
.It Dv KERN_FILE_BYFILE
-all open files
+all open files with type
+.Fa arg
+(0 for all files)
.It Dv KERN_FILE_BYPID
files opened by process ID
.Fa arg
@@ -70,11 +72,30 @@ files opened by process ID
.It Dv KERN_FILE_BYUID
files opened by processes with effective user ID
.Fa arg
+(\-1 for all users)
.El
.Pp
Files associated with a process will include information about
the process that has the file open.
.Pp
+For
+.Dv KERN_FILE_BYFILE
+the recognized file types are defined in
+.In sys/file.h :
+.Pp
+.Bl -tag -width 20n -offset indent -compact
+.It Dv DTYPE_VNODE
+files and devices
+.It Dv DTYPE_SOCKET
+sockets, regardless of domain
+.It Dv DTYPE_PIPE
+pipes and FIFOs
+.It Dv DTYPE_KQUEUE
+kqueues
+.It Dv DTYPE_SYSTRACE
+systrace control files
+.El
+.Pp
Only the first
.Fa elemsize
bytes of each array entry are returned.