diff options
-rw-r--r-- | include/kvm.h | 7 | ||||
-rw-r--r-- | lib/libc/gen/sysctl.3 | 32 | ||||
-rw-r--r-- | lib/libkvm/Makefile | 5 | ||||
-rw-r--r-- | lib/libkvm/kvm_cd9660.c | 4 | ||||
-rw-r--r-- | lib/libkvm/kvm_file.c | 176 | ||||
-rw-r--r-- | lib/libkvm/kvm_file2.c | 102 | ||||
-rw-r--r-- | lib/libkvm/kvm_getfiles.3 | 65 | ||||
-rw-r--r-- | lib/libkvm/kvm_ntfs.c | 4 | ||||
-rw-r--r-- | lib/libkvm/kvm_private.h | 8 | ||||
-rw-r--r-- | lib/libkvm/kvm_udf.c | 4 | ||||
-rw-r--r-- | lib/libkvm/shlib_version | 2 | ||||
-rw-r--r-- | sbin/sysctl/sysctl.c | 5 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 103 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 25 | ||||
-rw-r--r-- | usr.bin/fstat/fstat.c | 60 | ||||
-rw-r--r-- | usr.bin/fstat/fstat.h | 2 | ||||
-rw-r--r-- | usr.bin/fstat/fuser.c | 8 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 17 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 6 | ||||
-rw-r--r-- | usr.bin/netstat/unix.c | 78 | ||||
-rw-r--r-- | usr.sbin/pstat/pstat.c | 8 |
21 files changed, 236 insertions, 485 deletions
diff --git a/include/kvm.h b/include/kvm.h index ea7e2cd657b..9c832392294 100644 --- a/include/kvm.h +++ b/include/kvm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm.h,v 1.17 2012/12/05 23:19:57 deraadt Exp $ */ +/* $OpenBSD: kvm.h,v 1.18 2013/10/22 16:40:25 guenther Exp $ */ /* $NetBSD: kvm.h,v 1.7 1996/04/19 12:02:50 leo Exp $ */ /*- @@ -61,9 +61,8 @@ char **kvm_getargv(kvm_t *, const struct kinfo_proc *, int); char **kvm_getenvv(kvm_t *, const struct kinfo_proc *, int); char *kvm_geterr(kvm_t *); int kvm_getloadavg(kvm_t *, double [], int); -char *kvm_getfiles(kvm_t *, int, int, int *); -struct kinfo_file2 * - kvm_getfile2(kvm_t *, int, int, size_t, int *); +struct kinfo_file * + kvm_getfiles(kvm_t *, int, int, size_t, int *); struct kinfo_proc * kvm_getprocs(kvm_t *, int, int, size_t, int *); int kvm_nlist(kvm_t *, struct nlist *); diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3 index da30c3ebe7e..aff15323264 100644 --- a/lib/libc/gen/sysctl.3 +++ b/lib/libc/gen/sysctl.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysctl.3,v 1.225 2013/06/09 15:09:20 jmc Exp $ +.\" $OpenBSD: sysctl.3,v 1.226 2013/10/22 16:40:28 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: June 9 2013 $ +.Dd $Mdocdate: October 22 2013 $ .Dt SYSCTL 3 .Os .Sh NAME @@ -408,8 +408,7 @@ information. .It Dv KERN_CRYPTODEVALLOWSOFT Ta "integer" Ta "yes" .It Dv KERN_DOMAINNAME Ta "string" Ta "yes" .It Dv KERN_EMUL Ta "node" Ta "not applicable" -.It Dv KERN_FILE Ta "struct file" Ta "no" -.It Dv KERN_FILE2 Ta "struct kinfo_file2" Ta "no" +.It Dv KERN_FILE Ta "struct kinfo_file" Ta "no" .It Dv KERN_FORKSTAT Ta "struct forkstat" Ta "no" .It Dv KERN_FSCALE Ta "integer" Ta "no" .It Dv KERN_FSYNC Ta "integer" Ta "no" @@ -546,22 +545,11 @@ which is an adjustable integer. Note that using this interface exposes duplicate entries which are consolidated by the userland frontend. .It Dv KERN_FILE -Return the entire file table. -This name is deprecated, as the layout of the returned structures -is not a stable ABI; use -.Dv KERN_FILE2 -instead. -The returned data consists of a single -.Li struct filehead -followed by an array of -.Li struct file , -whose size depends on the current number of such objects in the system. -.It Dv KERN_FILE2 -Like -.Dv KERN_FILE -but an array of -.Li struct kinfo_file2 -structures is returned. +Return the entire file table, or a subset of it. +An array of +.Li struct kinfo_file +structures is returned, +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:" @@ -571,7 +559,7 @@ The third and fourth level names are as follows: .El .Pp The fifth level name is the size of the -.Li struct kinfo_file2 +.Li struct kinfo_file and the sixth level name is the number of structures to return. .It Dv KERN_FORKSTAT A @@ -706,7 +694,7 @@ Return the entire process table, or a subset of it. An array of .Li struct kinfo_proc structures is returned, -whose size depends on the current number of such objects in the system. +whose size depends on the current number of selected processes in the system. The third and fourth level names are as follows: .Bl -column "KERN_PROC_SESSION" "Fourth level is:" -offset indent .It Sy "Third level name" Ta Sy "Fourth level is:" diff --git a/lib/libkvm/Makefile b/lib/libkvm/Makefile index 7a4fd78d2fa..d8e5d4ac878 100644 --- a/lib/libkvm/Makefile +++ b/lib/libkvm/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.16 2012/08/02 13:38:38 okan Exp $ +# $OpenBSD: Makefile,v 1.17 2013/10/22 16:40:26 guenther Exp $ # $NetBSD: Makefile,v 1.11 1996/03/18 22:33:07 thorpej Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/4/93 @@ -19,14 +19,13 @@ SRCS= kvm_${MACHINE_CPU}.c .endif CFLAGS+= -D_LIBKVM -SRCS+= kvm.c kvm_file.c kvm_file2.c kvm_getloadavg.c kvm_proc.c kvm_proc2.c \ +SRCS+= kvm.c kvm_file2.c kvm_getloadavg.c kvm_proc.c kvm_proc2.c \ kvm_cd9660.c kvm_udf.c kvm_ntfs.c MAN= kvm.3 kvm_dump.3 kvm_geterr.3 kvm_getfiles.3 kvm_getloadavg.3 \ kvm_getprocs.3 kvm_nlist.3 kvm_open.3 kvm_read.3 MLINKS+=kvm_getprocs.3 kvm_getargv.3 kvm_getprocs.3 kvm_getenvv.3 -MLINKS+=kvm_getfiles.3 kvm_getfile2.3 MLINKS+=kvm_open.3 kvm_openfiles.3 kvm_open.3 kvm_close.3 MLINKS+=kvm_read.3 kvm_write.3 MLINKS+=kvm_dump.3 kvm_dump_mkheader.3 kvm_dump.3 kvm_dump_wrtheader.3 diff --git a/lib/libkvm/kvm_cd9660.c b/lib/libkvm/kvm_cd9660.c index 27a8d823458..18218f3363c 100644 --- a/lib/libkvm/kvm_cd9660.c +++ b/lib/libkvm/kvm_cd9660.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_cd9660.c,v 1.3 2009/10/27 23:59:28 deraadt Exp $ */ +/* $OpenBSD: kvm_cd9660.c,v 1.4 2013/10/22 16:40:26 guenther Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -35,7 +35,7 @@ #include "kvm_private.h" int -_kvm_stat_cd9660(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +_kvm_stat_cd9660(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct iso_node inode; diff --git a/lib/libkvm/kvm_file.c b/lib/libkvm/kvm_file.c deleted file mode 100644 index b0b520bcdc5..00000000000 --- a/lib/libkvm/kvm_file.c +++ /dev/null @@ -1,176 +0,0 @@ -/* $OpenBSD: kvm_file.c,v 1.16 2009/10/27 23:59:28 deraadt Exp $ */ -/* $NetBSD: kvm_file.c,v 1.5 1996/03/18 22:33:18 thorpej Exp $ */ - -/*- - * Copyright (c) 1989, 1992, 1993 - * The Regents of the University of California. 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - */ - -/* - * File list interface for kvm. pstat, fstat and netstat are - * users of this code, so we've factored it out into a separate module. - * Thus, we keep this grunge out of the other kvm applications (i.e., - * most other applications are interested only in open/close/read/nlist). - */ - -#include <sys/param.h> -#include <sys/user.h> -#include <sys/proc.h> -#include <sys/exec.h> -#define _KERNEL -#include <sys/file.h> -#undef _KERNEL -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <sys/tty.h> -#include <nlist.h> -#include <kvm.h> - -#include <sys/sysctl.h> - -#include <limits.h> -#include <db.h> -#include <paths.h> - -#include "kvm_private.h" - -static int kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o, - int nfiles); - -/* - * Get file structures. - */ -static int -kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o, int kvm_nfiles) -{ - int buflen = kd->arglen, n = 0; - char *where = kd->argspc; - struct file *fp; - struct filelist kvm_filehead; - - /* - * first copyout filehead - */ - if (buflen > sizeof (kvm_filehead)) { - if (KREAD(kd, filehead_o, &kvm_filehead)) { - _kvm_err(kd, kd->program, "can't read filehead"); - return (0); - } - buflen -= sizeof(kvm_filehead); - where += sizeof(kvm_filehead); - *(struct filelist *)kd->argspc = kvm_filehead; - } - /* - * followed by an array of file structures - */ - LIST_FOREACH(fp, &kvm_filehead, f_list) { - if (buflen > sizeof (struct file)) { - if (KREAD(kd, (long)fp, ((struct file *)where))) { - _kvm_err(kd, kd->program, "can't read kfp"); - return (0); - } - buflen -= sizeof (struct file); - fp = (struct file *)where; - where += sizeof (struct file); - n++; - } - } - if (n != kvm_nfiles) { - _kvm_err(kd, kd->program, "inconsistent nfiles"); - return (0); - } - return (kvm_nfiles); -} - -char * -kvm_getfiles(kvm_t *kd, int op, int arg, int *cnt) -{ - struct filelist kvm_filehead; - struct file *fp, *fplim; - int mib[2], st, kvm_nfiles; - size_t size; - - if (ISALIVE(kd)) { - size = 0; - mib[0] = CTL_KERN; - mib[1] = KERN_FILE; - st = sysctl(mib, 2, NULL, &size, NULL, 0); - if (st == -1) { - _kvm_syserr(kd, kd->program, "kvm_getfiles"); - return (0); - } - if (kd->argspc == 0) - kd->argspc = (char *)_kvm_malloc(kd, size); - else if (kd->arglen < size) - kd->argspc = (char *)_kvm_realloc(kd, kd->argspc, size); - if (kd->argspc == 0) - return (0); - kd->arglen = size; - st = sysctl(mib, 2, kd->argspc, &size, NULL, 0); - if (st == -1 || size < sizeof(kvm_filehead)) { - _kvm_syserr(kd, kd->program, "kvm_getfiles"); - return (0); - } - kvm_filehead = *(struct filelist *)kd->argspc; - fp = (struct file *)(kd->argspc + sizeof(kvm_filehead)); - fplim = (struct file *)(kd->argspc + size); - for (kvm_nfiles = 0; LIST_FIRST(&kvm_filehead) && (fp < fplim); - kvm_nfiles++, fp++) - LIST_FIRST(&kvm_filehead) = LIST_NEXT(fp, f_list); - } else { - struct nlist nl[3], *p; - - nl[0].n_name = "_filehead"; - nl[1].n_name = "_nfiles"; - nl[2].n_name = 0; - - if (kvm_nlist(kd, nl) != 0) { - for (p = nl; p->n_type != 0; ++p) - ; - _kvm_err(kd, kd->program, - "%s: no such symbol", p->n_name); - return (0); - } - if (KREAD(kd, nl[0].n_value, &kvm_nfiles)) { - _kvm_err(kd, kd->program, "can't read nfiles"); - return (0); - } - size = sizeof(kvm_filehead) + (kvm_nfiles + 10) * sizeof(struct file); - if (kd->argspc == 0) - kd->argspc = (char *)_kvm_malloc(kd, size); - else if (kd->arglen < size) - kd->argspc = (char *)_kvm_realloc(kd, kd->argspc, size); - if (kd->argspc == 0) - return (0); - kd->arglen = size; - kvm_nfiles = kvm_deadfiles(kd, op, arg, nl[1].n_value, kvm_nfiles); - if (kvm_nfiles == 0) - return (0); - } - *cnt = kvm_nfiles; - return (kd->argspc); -} diff --git a/lib/libkvm/kvm_file2.c b/lib/libkvm/kvm_file2.c index 5a5eb9efeb0..eef2c41ce32 100644 --- a/lib/libkvm/kvm_file2.c +++ b/lib/libkvm/kvm_file2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_file2.c,v 1.27 2013/03/20 14:46:45 deraadt Exp $ */ +/* $OpenBSD: kvm_file2.c,v 1.28 2013/10/22 16:40:26 guenther Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -70,8 +70,10 @@ #include <sys/protosw.h> #include <sys/event.h> #include <sys/eventvar.h> +#include <sys/un.h> #include <sys/unpcb.h> #include <sys/filedesc.h> +#include <sys/mbuf.h> #include <sys/pipe.h> #include <sys/stat.h> #include <sys/sysctl.h> @@ -105,6 +107,7 @@ #include <nlist.h> #include <kvm.h> #include <db.h> +#include <stddef.h> #include <stdlib.h> #include <stddef.h> #include <string.h> @@ -112,18 +115,18 @@ #include "kvm_private.h" -static struct kinfo_file2 *kvm_deadfile2_byfile(kvm_t *, int, int, +static struct kinfo_file *kvm_deadfile_byfile(kvm_t *, int, int, size_t, int *); -static struct kinfo_file2 *kvm_deadfile2_byid(kvm_t *, int, int, +static struct kinfo_file *kvm_deadfile_byid(kvm_t *, int, int, size_t, int *); -static int fill_file2(kvm_t *, struct kinfo_file2 *, struct file *, u_long, +static int fill_file(kvm_t *, struct kinfo_file *, struct file *, u_long, struct vnode *, struct proc *, int, pid_t); -static int filestat(kvm_t *, struct kinfo_file2 *, struct vnode *); +static int filestat(kvm_t *, struct kinfo_file *, struct vnode *); LIST_HEAD(proclist, proc); -struct kinfo_file2 * -kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) +struct kinfo_file * +kvm_getfiles(kvm_t *kd, int op, int arg, size_t esize, int *cnt) { int mib[6], rv; size_t size; @@ -139,7 +142,7 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) if (ISALIVE(kd)) { mib[0] = CTL_KERN; - mib[1] = KERN_FILE2; + mib[1] = KERN_FILE; mib[2] = op; mib[3] = arg; mib[4] = esize; @@ -150,7 +153,7 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) if (rv == -1) { if (kd->vmfd != -1) goto deadway; - _kvm_syserr(kd, kd->program, "kvm_getfile2"); + _kvm_syserr(kd, kd->program, "kvm_getfiles"); return (NULL); } kd->filebase = _kvm_malloc(kd, size); @@ -161,15 +164,15 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) mib[5] = size / esize; rv = sysctl(mib, 6, kd->filebase, &size, NULL, 0); if (rv == -1) { - _kvm_syserr(kd, kd->program, "kvm_getfile2"); + _kvm_syserr(kd, kd->program, "kvm_getfiles"); return (NULL); } *cnt = size / esize; - return ((struct kinfo_file2 *)kd->filebase); + return ((struct kinfo_file *)kd->filebase); } else { - if (esize > sizeof(struct kinfo_file2)) { + if (esize > sizeof(struct kinfo_file)) { _kvm_syserr(kd, kd->program, - "kvm_getfile2: unknown fields requested: libkvm out of date?"); + "kvm_getfiles: unknown fields requested: libkvm out of date?"); return (NULL); } deadway: @@ -180,11 +183,11 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) "%s: invalid argument"); return (NULL); } - return (kvm_deadfile2_byfile(kd, op, arg, esize, cnt)); + return (kvm_deadfile_byfile(kd, op, arg, esize, cnt)); break; case KERN_FILE_BYPID: case KERN_FILE_BYUID: - return (kvm_deadfile2_byid(kd, op, arg, esize, cnt)); + return (kvm_deadfile_byid(kd, op, arg, esize, cnt)); break; default: return (NULL); @@ -192,14 +195,14 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) } } -static struct kinfo_file2 * -kvm_deadfile2_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt) +static struct kinfo_file * +kvm_deadfile_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt) { struct nlist nl[3], *p; size_t buflen; int n = 0; char *where; - struct kinfo_file2 kf; + struct kinfo_file kf; struct file *fp, file; struct filelist filehead; int nfiles; @@ -236,7 +239,7 @@ kvm_deadfile2_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 (fill_file2(kd, &kf, &file, (u_long)fp, NULL, NULL, 0, 0) + if (fill_file(kd, &kf, &file, (u_long)fp, NULL, NULL, 0, 0) == -1) return (NULL); memcpy(where, &kf, esize); @@ -249,17 +252,17 @@ kvm_deadfile2_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt) return (NULL); } *cnt = n; - return ((struct kinfo_file2 *)kd->filebase); + return ((struct kinfo_file *)kd->filebase); } -static struct kinfo_file2 * -kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) +static struct kinfo_file * +kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) { size_t buflen; struct nlist nl[4], *np; int n = 0; char *where; - struct kinfo_file2 kf; + struct kinfo_file kf; struct file *fp, file; struct filelist filehead; struct filedesc0 filed0; @@ -389,7 +392,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) if (proc.p_textvp) { if (buflen < esize) goto done; - if (fill_file2(kd, &kf, NULL, 0, proc.p_textvp, &proc, + if (fill_file(kd, &kf, NULL, 0, proc.p_textvp, &proc, KERN_FILE_TEXT, pid) == -1) goto cleanup; memcpy(where, &kf, esize); @@ -400,7 +403,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) if (filed.fd_cdir) { if (buflen < esize) goto done; - if (fill_file2(kd, &kf, NULL, 0, filed.fd_cdir, &proc, + if (fill_file(kd, &kf, NULL, 0, filed.fd_cdir, &proc, KERN_FILE_CDIR, pid) == -1) goto cleanup; memcpy(where, &kf, esize); @@ -411,7 +414,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) if (filed.fd_rdir) { if (buflen < esize) goto done; - if (fill_file2(kd, &kf, NULL, 0, filed.fd_rdir, &proc, + if (fill_file(kd, &kf, NULL, 0, filed.fd_rdir, &proc, KERN_FILE_RDIR, pid) == -1) goto cleanup; memcpy(where, &kf, esize); @@ -422,7 +425,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) if (process.ps_tracevp) { if (buflen < esize) goto done; - if (fill_file2(kd, &kf, NULL, 0, process.ps_tracevp, + if (fill_file(kd, &kf, NULL, 0, process.ps_tracevp, &proc, KERN_FILE_TRACE, pid) == -1) goto cleanup; memcpy(where, &kf, esize); @@ -449,7 +452,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) _kvm_err(kd, kd->program, "can't read file"); goto cleanup; } - if (fill_file2(kd, &kf, &file, (u_long)fp, NULL, + if (fill_file(kd, &kf, &file, (u_long)fp, NULL, &proc, i, pid) == -1) goto cleanup; memcpy(where, &kf, esize); @@ -461,14 +464,14 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) done: *cnt = n; free(filebuf); - return ((struct kinfo_file2 *)kd->filebase); + return ((struct kinfo_file *)kd->filebase); cleanup: free(filebuf); return (NULL); } static int -fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, u_long fpaddr, struct vnode *vp, +fill_file(kvm_t *kd, struct kinfo_file *kf, struct file *fp, u_long fpaddr, struct vnode *vp, struct proc *p, int fd, pid_t pid) { struct ucred f_cred; @@ -570,6 +573,8 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, u_long fpaddr, st return (-1); } kf->so_family = domain.dom_family; + kf->so_rcv_cc = sock.so_rcv.sb_cc; + kf->so_snd_cc = sock.so_snd.sb_cc; if (sock.so_splice) { kf->so_splice = PTRTOINT64(sock.so_splice); kf->so_splicelen = sock.so_splicelen; @@ -622,7 +627,30 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, u_long fpaddr, st _kvm_err(kd, kd->program, "can't read unpcb"); return (-1); } - kf->unp_conn = PTRTOINT64(unpcb.unp_conn); + kf->unp_conn = PTRTOINT64(unpcb.unp_conn); + kf->unp_refs = PTRTOINT64(unpcb.unp_refs); + kf->unp_nextref = PTRTOINT64(unpcb.unp_nextref); + kf->v_un = PTRTOINT64(unpcb.unp_vnode); + if (unpcb.unp_addr != NULL) { + struct mbuf mb; + struct sockaddr_un un; + + if (KREAD(kd, (u_long)unpcb.unp_addr, &mb)) { + _kvm_err(kd, kd->program, + "can't read sockaddr_un mbuf"); + return (-1); + } + if (KREAD(kd, (u_long)mb.m_data, &un)) { + _kvm_err(kd, kd->program, + "can't read sockaddr_un"); + return (-1); + } + + kf->unp_addr = PTRTOINT64(unpcb.unp_addr); + memcpy(kf->unp_path, un.sun_path, un.sun_len + - offsetof(struct sockaddr_un,sun_path)); + } + break; } } @@ -714,7 +742,7 @@ _kvm_getftype(enum vtype v_type) } static int -ufs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +ufs_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct inode inode; struct ufs1_dinode di1; @@ -742,7 +770,7 @@ ufs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) } static int -ext2fs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +ext2fs_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct inode inode; struct ext2fs_dinode e2di; @@ -770,7 +798,7 @@ ext2fs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) } static int -msdos_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +msdos_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct denode de; struct msdosfsmount mp; @@ -795,7 +823,7 @@ msdos_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) } static int -nfs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +nfs_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct nfsnode nfsnode; @@ -814,7 +842,7 @@ nfs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) } static int -spec_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +spec_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct specinfo specinfo; struct vnode parent; @@ -840,7 +868,7 @@ spec_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) } static int -filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { int ret = 0; diff --git a/lib/libkvm/kvm_getfiles.3 b/lib/libkvm/kvm_getfiles.3 index 6954f5aa60b..f26818fcdc4 100644 --- a/lib/libkvm/kvm_getfiles.3 +++ b/lib/libkvm/kvm_getfiles.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kvm_getfiles.3,v 1.15 2013/08/03 06:25:32 guenther Exp $ +.\" $OpenBSD: kvm_getfiles.3,v 1.16 2013/10/22 16:40:27 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: August 3 2013 $ +.Dd $Mdocdate: October 22 2013 $ .Dt KVM_GETFILES 3 .Os .Sh NAME @@ -43,14 +43,9 @@ .Sh SYNOPSIS .In kvm.h .In sys/types.h -.Fd #define _KERNEL -.In sys/file.h -.Fd #undef _KERNEL -.\" .Fa kvm_t *kd -.Ft char * -.Fn kvm_getfiles "kvm_t *kd" "int op" "int arg" "int *cnt" -.Ft struct kinfo_file2 * -.Fn kvm_getfile2 "kvm_t *kd" "int op" "int arg" "size_t elemsize" "int *cnt" +.In sys/sysctl.h +.Ft struct kinfo_file * +.Fn kvm_getfiles "kvm_t *kd" "int op" "int arg" "size_t elemsize" "int *cnt" .Sh DESCRIPTION .Fn kvm_getfiles returns a (sub-)set of the open files in the kernel indicated by @@ -61,38 +56,6 @@ and .Fa arg arguments constitute a predicate which limits the set of files returned. -No predicates are currently defined. -.Pp -The number of processes found is returned in the reference parameter -.Fa cnt . -The files are returned as a contiguous array of file structures, -preceded by the address of the first file entry in the kernel. -This memory is owned by kvm and is not guaranteed to be persistent across -subsequent kvm library calls. -Data should be copied out if it needs to be saved. -.Pp -.Fn kvm_getfile2 -is similar to -.Fn kvm_getfiles -but returns an array of -.Vt kinfo_file2 -structures. -Additionally, only the first -.Fa elemsize -bytes of each array entry are returned. -If the size of the -.Vt kinfo_file2 -structure increases in size in a future release of -.Ox , -the kernel will only return the requested amount of data for -each array entry and programs that use -.Fn kvm_getfile2 -will continue to function without the need for recompilation. -The -.Fa op -and -.Fa arg -arguments constitute a predicate which limits the set of processes returned. The value of .Fa op describes the filtering predicate as follows: @@ -112,20 +75,30 @@ files opened by processes with effective user ID Files associated with a process will include information about the process that has the file open. .Pp +Only the first +.Fa elemsize +bytes of each array entry are returned. +If the size of the +.Vt kinfo_file +structure increases in size in a future release of +.Ox , +the kernel will only return the requested amount of data for +each array entry and programs that use +.Fn kvm_getfiles +will continue to function without the need for recompilation. +.Pp The files are returned as a contiguous array of -.Vt kinfo_file2 +.Vt kinfo_file structures. The number of structures found is returned in the reference parameter .Fa cnt . This memory is owned by kvm and will be overwritten by subsequent calls to -.Fn kvm_getfile2 +.Fn kvm_getfiles and destroyed by .Fn kvm_close . Data should be copied out if it needs to be saved. .Sh RETURN VALUES .Fn kvm_getfiles -and -.Fn kvm_getfile2 will return .Dv NULL on failure. diff --git a/lib/libkvm/kvm_ntfs.c b/lib/libkvm/kvm_ntfs.c index 53a7c19209d..f8530771ec0 100644 --- a/lib/libkvm/kvm_ntfs.c +++ b/lib/libkvm/kvm_ntfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_ntfs.c,v 1.2 2009/10/27 23:59:28 deraadt Exp $ */ +/* $OpenBSD: kvm_ntfs.c,v 1.3 2013/10/22 16:40:27 guenther Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -49,7 +49,7 @@ extern mode_t _kvm_getftype(enum vtype); int -_kvm_stat_ntfs(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +_kvm_stat_ntfs(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct ntnode ntnode; struct fnode fn; diff --git a/lib/libkvm/kvm_private.h b/lib/libkvm/kvm_private.h index b25b7f0804c..409bace43ad 100644 --- a/lib/libkvm/kvm_private.h +++ b/lib/libkvm/kvm_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_private.h,v 1.17 2011/03/12 04:54:28 guenther Exp $ */ +/* $OpenBSD: kvm_private.h,v 1.18 2013/10/22 16:40:27 guenther Exp $ */ /* $NetBSD: kvm_private.h,v 1.7 1996/05/05 04:32:15 gwr Exp $ */ /*- @@ -101,6 +101,6 @@ void *_kvm_realloc(kvm_t *kd, void *, size_t); void _kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...); ssize_t _kvm_pread(kvm_t *, int, void *, size_t, off_t); ssize_t _kvm_pwrite(kvm_t *, int, const void *, size_t, off_t); -int _kvm_stat_cd9660(kvm_t *, struct kinfo_file2 *, struct vnode *); -int _kvm_stat_udf(kvm_t *, struct kinfo_file2 *, struct vnode *); -int _kvm_stat_ntfs(kvm_t *, struct kinfo_file2 *, struct vnode *); +int _kvm_stat_cd9660(kvm_t *, struct kinfo_file *, struct vnode *); +int _kvm_stat_udf(kvm_t *, struct kinfo_file *, struct vnode *); +int _kvm_stat_ntfs(kvm_t *, struct kinfo_file *, struct vnode *); diff --git a/lib/libkvm/kvm_udf.c b/lib/libkvm/kvm_udf.c index 470a4fe062e..3907ebc5c13 100644 --- a/lib/libkvm/kvm_udf.c +++ b/lib/libkvm/kvm_udf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_udf.c,v 1.5 2013/03/23 17:11:08 deraadt Exp $ */ +/* $OpenBSD: kvm_udf.c,v 1.6 2013/10/22 16:40:27 guenther Exp $ */ /* * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org> @@ -67,7 +67,7 @@ udf_permtomode(struct unode *up) } int -_kvm_stat_udf(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp) +_kvm_stat_udf(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp) { struct unode up; struct file_entry fentry; diff --git a/lib/libkvm/shlib_version b/lib/libkvm/shlib_version index d85251eba7d..77913220429 100644 --- a/lib/libkvm/shlib_version +++ b/lib/libkvm/shlib_version @@ -1,2 +1,2 @@ -major=14 +major=15 minor=0 diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index e5df3e3c385..74ecbc7b574 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.c,v 1.194 2013/07/18 05:02:57 guenther Exp $ */ +/* $OpenBSD: sysctl.c,v 1.195 2013/10/22 16:40:28 guenther Exp $ */ /* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */ /* @@ -387,7 +387,6 @@ parse(char *string, int flags) warnx("use dmesg to view %s", string); return; case KERN_VNODE: - case KERN_FILE: if (flags == 0) return; warnx("use pstat to view %s information", string); @@ -439,7 +438,7 @@ parse(char *string, int flags) case KERN_EMUL: sysctl_emul(string, newval, flags); return; - case KERN_FILE2: + case KERN_FILE: if (flags == 0) return; warnx("use fstat to view %s information", string); diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 3781a4c02fc..e21e17708e3 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.240 2013/07/09 15:37:43 beck Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.241 2013/10/22 16:40:26 guenther Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -72,6 +72,7 @@ #include <sys/protosw.h> #include <sys/timetc.h> #include <sys/evcount.h> +#include <sys/un.h> #include <sys/unpcb.h> #include <sys/mount.h> @@ -121,7 +122,7 @@ int sysctl_sensors(int *, u_int, void *, size_t *, void *, size_t); int sysctl_emul(int *, u_int, void *, size_t *, void *, size_t); int sysctl_cptime2(int *, u_int, void *, size_t *, void *, size_t); -void fill_file2(struct kinfo_file2 *, struct file *, struct filedesc *, +void fill_file(struct kinfo_file *, struct file *, struct filedesc *, int, struct vnode *, struct proc *, struct proc *, int); void fill_kproc(struct proc *, struct kinfo_proc *, int, int); @@ -293,7 +294,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_EVCOUNT: case KERN_TIMECOUNTER: case KERN_CPTIME2: - case KERN_FILE2: + case KERN_FILE: break; default: return (ENOTDIR); /* overloaded */ @@ -372,11 +373,9 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_PROC_CWD: return (sysctl_proc_cwd(name + 1, namelen - 1, oldp, oldlenp, p)); - case KERN_FILE2: - return (sysctl_file2(name + 1, namelen - 1, oldp, oldlenp, p)); -#endif case KERN_FILE: - return (sysctl_file(oldp, oldlenp, p)); + return (sysctl_file(name + 1, namelen - 1, oldp, oldlenp, p)); +#endif case KERN_MBSTAT: return (sysctl_rdstruct(oldp, oldlenp, newp, &mbstat, sizeof(mbstat))); @@ -993,72 +992,9 @@ sysctl_rdstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp, return (error); } -/* - * Get file structures. - */ -int -sysctl_file(char *where, size_t *sizep, struct proc *p) -{ - int buflen, error; - struct file *fp, cfile; - char *start = where; - struct ucred *cred = p->p_ucred; - - buflen = *sizep; - if (where == NULL) { - /* - * overestimate by KERN_FILESLOP files - */ - *sizep = sizeof(filehead) + - (nfiles + KERN_FILESLOP) * sizeof(struct file); - return (0); - } - - /* - * first copyout filehead - */ - if (buflen < sizeof(filehead)) { - *sizep = 0; - return (0); - } - error = copyout((caddr_t)&filehead, where, sizeof(filehead)); - if (error) - return (error); - buflen -= sizeof(filehead); - where += sizeof(filehead); - - /* - * followed by an array of file structures - */ - LIST_FOREACH(fp, &filehead, f_list) { - if (buflen < sizeof(struct file)) { - *sizep = where - start; - return (ENOMEM); - } - - /* Only let the superuser or the owner see some information */ - bcopy(fp, &cfile, sizeof (struct file)); - if (suser(p, 0) != 0 && cred->cr_uid != fp->f_cred->cr_uid) { - cfile.f_offset = (off_t)-1; - cfile.f_rxfer = 0; - cfile.f_wxfer = 0; - cfile.f_seek = 0; - cfile.f_rbytes = 0; - cfile.f_wbytes = 0; - } - error = copyout(&cfile, where, sizeof (struct file)); - if (error) - return (error); - buflen -= sizeof(struct file); - where += sizeof(struct file); - } - *sizep = where - start; - return (0); -} - #ifndef SMALL_KERNEL void -fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, +fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp, int fd, struct vnode *vp, struct proc *pp, struct proc *p, int show_pointers) { @@ -1139,8 +1075,12 @@ fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, kf->so_state = so->so_state; if (show_pointers) kf->so_pcb = PTRTOINT64(so->so_pcb); + else + kf->so_pcb = -1; kf->so_protocol = so->so_proto->pr_protocol; kf->so_family = so->so_proto->pr_domain->dom_family; + kf->so_rcv_cc = so->so_rcv.sb_cc; + kf->so_snd_cc = so->so_snd.sb_cc; if (so->so_splice) { if (show_pointers) kf->so_splice = PTRTOINT64(so->so_splice); @@ -1182,8 +1122,19 @@ fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, case AF_UNIX: { struct unpcb *unpcb = so->so_pcb; - if (show_pointers) - kf->unp_conn = PTRTOINT64(unpcb->unp_conn); + if (show_pointers) { + kf->unp_conn = PTRTOINT64(unpcb->unp_conn); + kf->unp_refs = PTRTOINT64(unpcb->unp_refs); + kf->unp_nextref = PTRTOINT64(unpcb->unp_nextref); + kf->v_un = PTRTOINT64(unpcb->unp_vnode); + kf->unp_addr = PTRTOINT64(unpcb->unp_addr); + } + if (unpcb->unp_addr != NULL) { + struct sockaddr_un *un = mtod(unpcb->unp_addr, + struct sockaddr_un *); + memcpy(kf->unp_path, un->sun_path, un->sun_len + - offsetof(struct sockaddr_un,sun_path)); + } break; } } @@ -1230,10 +1181,10 @@ fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, * Get file structures. */ int -sysctl_file2(int *name, u_int namelen, char *where, size_t *sizep, +sysctl_file(int *name, u_int namelen, char *where, size_t *sizep, struct proc *p) { - struct kinfo_file2 *kf; + struct kinfo_file *kf; struct filedesc *fdp; struct file *fp; struct proc *pp; @@ -1264,7 +1215,7 @@ sysctl_file2(int *name, u_int namelen, char *where, size_t *sizep, #define FILLIT(fp, fdp, i, vp, pp) do { \ if (buflen >= elem_size && elem_count > 0) { \ - fill_file2(kf, fp, fdp, i, vp, pp, p, show_pointers); \ + fill_file(kf, fp, fdp, i, vp, pp, p, show_pointers); \ error = copyout(kf, dp, outsize); \ if (error) \ break; \ diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 19bfee3c48e..02317a71132 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.138 2013/09/22 17:28:33 guenther Exp $ */ +/* $OpenBSD: sysctl.h,v 1.139 2013/10/22 16:40:26 guenther Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -115,7 +115,7 @@ struct ctlname { #define KERN_CLOCKRATE 12 /* struct: struct clockinfo */ #define KERN_VNODE 13 /* struct: vnode structures */ /*define gap: was KERN_PROC 14 */ -#define KERN_FILE 15 /* struct: file entries */ +/*define gap: was KERN_FILE 15 */ #define KERN_PROF 16 /* node: kernel profiling info */ #define KERN_POSIX1 17 /* int: POSIX.1 version */ #define KERN_NGROUPS 18 /* int: # of supplemental group ids */ @@ -173,7 +173,7 @@ struct ctlname { #define KERN_MAXLOCKSPERUID 70 /* int: locks per uid */ #define KERN_CPTIME2 71 /* array: cp_time2 */ #define KERN_CACHEPCT 72 /* buffer cache % of physmem */ -#define KERN_FILE2 73 /* struct: file entries */ +#define KERN_FILE 73 /* struct: file entries */ /* was define KERN_RTHREADS 74 */ #define KERN_CONSDEV 75 /* dev_t: console terminal device */ #define KERN_NETLIVELOCKS 76 /* int: number of network livelocks */ @@ -197,7 +197,7 @@ struct ctlname { { "clockrate", CTLTYPE_STRUCT }, \ { "vnode", CTLTYPE_STRUCT }, \ { "gap", 0 }, \ - { "file", CTLTYPE_STRUCT }, \ + { "gap", 0 }, \ { "profiling", CTLTYPE_NODE }, \ { "posix1version", CTLTYPE_INT }, \ { "ngroups", CTLTYPE_INT }, \ @@ -255,7 +255,7 @@ struct ctlname { { "maxlocksperuid", CTLTYPE_INT }, \ { "cp_time2", CTLTYPE_STRUCT }, \ { "bufcachepercent", CTLTYPE_INT }, \ - { "file2", CTLTYPE_STRUCT }, \ + { "file", CTLTYPE_STRUCT }, \ { "gap", 0 }, \ { "consdev", CTLTYPE_STRUCT }, \ { "netlivelocks", CTLTYPE_INT }, \ @@ -608,7 +608,7 @@ do { \ /* - * kern.file2 returns an array of these structures, which are designed + * kern.file returns an array of these structures, which are designed * both to be immune to 32/64 bit emulation issues and to * provide backwards compatibility. The order differs slightly from * that of the real struct file, and some fields are taken from other @@ -626,8 +626,9 @@ do { \ #define KERN_FILE_TRACE -4 #define KI_MNAMELEN 96 /* rounded up from 90 */ +#define KI_UNPPATHLEN 104 -struct kinfo_file2 { +struct kinfo_file { uint64_t f_fileaddr; /* PTR: address of struct file */ uint32_t f_flag; /* SHORT: flags (see fcntl.h) */ uint32_t f_iflags; /* INT: internal flags */ @@ -665,6 +666,7 @@ struct kinfo_file2 { uint32_t so_type; /* SHORT: socket type */ uint32_t so_state; /* SHORT: socket state */ uint64_t so_pcb; /* PTR: socket pcb */ + /* for non-root: -1 if not NULL */ uint32_t so_protocol; /* SHORT: socket protocol type */ uint32_t so_family; /* INT: socket domain family */ uint64_t inp_ppcb; /* PTR: pointer to per-protocol pcb */ @@ -699,6 +701,12 @@ struct kinfo_file2 { uint64_t so_splice; /* PTR: f_data of spliced socket */ int64_t so_splicelen; /* OFF_T: already spliced count or */ /* -1 if this is target of splice */ + uint64_t so_rcv_cc; /* LONG: chars in receive buf */ + uint64_t so_snd_cc; /* LONG: chars in send buf */ + uint64_t unp_refs; /* PTR: connected sockets */ + uint64_t unp_nextref; /* PTR: link to next connected socket */ + uint64_t unp_addr; /* PTR: address of the socket address */ + char unp_path[KI_UNPPATHLEN]; }; /* @@ -879,8 +887,7 @@ int sysctl__string(void *, size_t *, void *, size_t, char *, int, int); int sysctl_rdstring(void *, size_t *, void *, const char *); int sysctl_rdstruct(void *, size_t *, void *, const void *, int); int sysctl_struct(void *, size_t *, void *, size_t, void *, int); -int sysctl_file(char *, size_t *, struct proc *); -int sysctl_file2(int *, u_int, char *, size_t *, struct proc *); +int sysctl_file(int *, u_int, char *, size_t *, struct proc *); int sysctl_doproc(int *, u_int, char *, size_t *); struct radix_node; struct walkarg; diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 1a07124cd5d..b670af9e343 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fstat.c,v 1.75 2013/03/31 01:42:28 bluhm Exp $ */ +/* $OpenBSD: fstat.c,v 1.76 2013/10/22 16:40:27 guenther Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -102,25 +102,25 @@ int signo; /* signal to send (fuser only) */ kvm_t *kd; uid_t uid; -void fstat_dofile(struct kinfo_file2 *); +void fstat_dofile(struct kinfo_file *); void fstat_header(void); void getinetproto(int); void usage(void); int getfname(char *); -void cryptotrans(struct kinfo_file2 *); -void kqueuetrans(struct kinfo_file2 *); -void pipetrans(struct kinfo_file2 *); -struct kinfo_file2 *splice_find(char, u_int64_t); -void splice_insert(char, u_int64_t, struct kinfo_file2 *); -void find_splices(struct kinfo_file2 *, int); -void print_inet_details(struct kinfo_file2 *); +void cryptotrans(struct kinfo_file *); +void kqueuetrans(struct kinfo_file *); +void pipetrans(struct kinfo_file *); +struct kinfo_file *splice_find(char, u_int64_t); +void splice_insert(char, u_int64_t, struct kinfo_file *); +void find_splices(struct kinfo_file *, int); +void print_inet_details(struct kinfo_file *); #ifdef INET6 -void print_inet6_details(struct kinfo_file2 *); +void print_inet6_details(struct kinfo_file *); #endif -void print_sock_details(struct kinfo_file2 *); -void socktrans(struct kinfo_file2 *); -void systracetrans(struct kinfo_file2 *); -void vtrans(struct kinfo_file2 *); +void print_sock_details(struct kinfo_file *); +void socktrans(struct kinfo_file *); +void systracetrans(struct kinfo_file *); +void vtrans(struct kinfo_file *); const char *inet6_addrstr(struct in6_addr *); int signame_to_signum(char *); void hide(void *p); @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { struct passwd *passwd; - struct kinfo_file2 *kf, *kflast; + struct kinfo_file *kf, *kflast; int arg, ch, what; char *memf, *nlistf, *optstr; char buf[_POSIX2_LINE_MAX]; @@ -271,7 +271,7 @@ main(int argc, char *argv[]) checkfile = 1; } - if ((kf = kvm_getfile2(kd, what, arg, sizeof(*kf), &cnt)) == NULL) + if ((kf = kvm_getfiles(kd, what, arg, sizeof(*kf), &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); find_splices(kf, cnt); @@ -336,7 +336,7 @@ pid_t Pid; * print open files attributed to this process */ void -fstat_dofile(struct kinfo_file2 *kf) +fstat_dofile(struct kinfo_file *kf) { Uname = user_from_uid(kf->p_uid, 0); @@ -378,7 +378,7 @@ fstat_dofile(struct kinfo_file2 *kf) } void -vtrans(struct kinfo_file2 *kf) +vtrans(struct kinfo_file *kf) { const char *badtype = NULL; char rw[3], mode[12]; @@ -471,7 +471,7 @@ vtrans(struct kinfo_file2 *kf) } void -pipetrans(struct kinfo_file2 *kf) +pipetrans(struct kinfo_file *kf) { void *maxaddr; @@ -502,7 +502,7 @@ pipetrans(struct kinfo_file2 *kf) } void -kqueuetrans(struct kinfo_file2 *kf) +kqueuetrans(struct kinfo_file *kf) { PREFIX(kf->fd_fd); @@ -518,7 +518,7 @@ kqueuetrans(struct kinfo_file2 *kf) } void -cryptotrans(struct kinfo_file2 *kf) +cryptotrans(struct kinfo_file *kf) { PREFIX(kf->fd_fd); @@ -530,7 +530,7 @@ cryptotrans(struct kinfo_file2 *kf) } void -systracetrans(struct kinfo_file2 *kf) +systracetrans(struct kinfo_file *kf) { PREFIX(kf->fd_fd); @@ -570,7 +570,7 @@ inet6_addrstr(struct in6_addr *p) #endif void -splice_insert(char type, u_int64_t ptr, struct kinfo_file2 *data) +splice_insert(char type, u_int64_t ptr, struct kinfo_file *data) { ENTRY entry, *found; @@ -584,7 +584,7 @@ splice_insert(char type, u_int64_t ptr, struct kinfo_file2 *data) found->data = NULL; } -struct kinfo_file2 * +struct kinfo_file * splice_find(char type, u_int64_t ptr) { ENTRY entry, *found; @@ -597,7 +597,7 @@ splice_find(char type, u_int64_t ptr) } void -find_splices(struct kinfo_file2 *kf, int cnt) +find_splices(struct kinfo_file *kf, int cnt) { int i, created; @@ -617,7 +617,7 @@ find_splices(struct kinfo_file2 *kf, int cnt) } void -print_inet_details(struct kinfo_file2 *kf) +print_inet_details(struct kinfo_file *kf) { struct in_addr laddr, faddr; @@ -653,7 +653,7 @@ print_inet_details(struct kinfo_file2 *kf) #ifdef INET6 void -print_inet6_details(struct kinfo_file2 *kf) +print_inet6_details(struct kinfo_file *kf) { char xaddrbuf[NI_MAXHOST + 2]; struct in6_addr laddr6, faddr6; @@ -700,7 +700,7 @@ print_inet6_details(struct kinfo_file2 *kf) #endif void -print_sock_details(struct kinfo_file2 *kf) +print_sock_details(struct kinfo_file *kf) { if (kf->so_family == AF_INET) print_inet_details(kf); @@ -711,7 +711,7 @@ print_sock_details(struct kinfo_file2 *kf) } void -socktrans(struct kinfo_file2 *kf) +socktrans(struct kinfo_file *kf) { static char *stypename[] = { "unused", /* 0 */ @@ -809,7 +809,7 @@ socktrans(struct kinfo_file2 *kf) hide((void *)(uintptr_t)kf->f_data); } if (kf->so_splice != 0 || kf->so_splicelen == -1) { - struct kinfo_file2 *from, *to; + struct kinfo_file *from, *to; from = splice_find('<', kf->f_data); to = NULL; diff --git a/usr.bin/fstat/fstat.h b/usr.bin/fstat/fstat.h index 6e2b230261f..573ee7a9a20 100644 --- a/usr.bin/fstat/fstat.h +++ b/usr.bin/fstat/fstat.h @@ -45,6 +45,6 @@ extern struct fileargs fileargs; extern char *__progname; -void fuser_check(struct kinfo_file2 *); +void fuser_check(struct kinfo_file *); void fuser_run(void); void usage(void); diff --git a/usr.bin/fstat/fuser.c b/usr.bin/fstat/fuser.c index 8486d33ac89..6713055c1db 100644 --- a/usr.bin/fstat/fuser.c +++ b/usr.bin/fstat/fuser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuser.c,v 1.2 2009/07/19 12:56:19 millert Exp $ */ +/* $OpenBSD: fuser.c,v 1.3 2013/10/22 16:40:28 guenther Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -65,7 +65,7 @@ * to a file held by a process (kf), else 0. */ static int -match(struct filearg *fa, struct kinfo_file2 *kf) +match(struct filearg *fa, struct kinfo_file *kf) { if (fa->dev == kf->va_fsid) { if (cflg) @@ -77,11 +77,11 @@ match(struct filearg *fa, struct kinfo_file2 *kf) } /* - * Examine kinfo_file2 struct and record the details if they + * Examine kinfo_file struct and record the details if they * match a watched file. */ void -fuser_check(struct kinfo_file2 *kf) +fuser_check(struct kinfo_file *kf) { struct filearg *fa; struct fuser *fu; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 88c0c694a64..9b2b62e4310 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.95 2013/03/20 15:23:37 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.96 2013/10/22 16:40:28 guenther Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -31,7 +31,6 @@ */ #include <sys/param.h> -#include <sys/file.h> #include <sys/protosw.h> #include <sys/socket.h> #include <sys/sysctl.h> @@ -42,6 +41,7 @@ #include <ctype.h> #include <err.h> #include <errno.h> +#include <fcntl.h> #include <kvm.h> #include <limits.h> #include <netdb.h> @@ -162,6 +162,7 @@ main(int argc, char *argv[]) u_int tableid; int Tflag = 0; int repeatcount = 0; + int need_nlist; hideroot = getuid(); @@ -331,6 +332,10 @@ main(int argc, char *argv[]) } #endif + need_nlist = !mflag && (pflag || nlistf != NULL || memf != NULL || + (!iflag && !sflag && (rflag ? Aflag : + (gflag || af != AF_UNIX || Pflag)))); + /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. @@ -341,8 +346,8 @@ main(int argc, char *argv[]) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); - if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, - buf)) == NULL) { + if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY | + (need_nlist ? 0 : KVM_NO_FILES), buf)) == NULL) { fprintf(stderr, "%s: kvm_openfiles: %s\n", __progname, buf); exit(1); } @@ -351,7 +356,7 @@ main(int argc, char *argv[]) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); - if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) { + if (need_nlist && (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0)) { if (nlistf) fprintf(stderr, "%s: %s: no namelist\n", __progname, nlistf); @@ -429,7 +434,7 @@ main(int argc, char *argv[]) printproto(tp, tp->pr_name, AF_INET6, tableid, pcbaddr); if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) - unixpr(nl[N_UNIXSW].n_value, pcbaddr); + unixpr(kvmd, pcbaddr); exit(0); } diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index bad8b97e271..539d9775d00 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.65 2013/03/20 15:23:37 deraadt Exp $ */ +/* $OpenBSD: netstat.h,v 1.66 2013/10/22 16:40:28 guenther Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -32,6 +32,8 @@ * from: @(#)netstat.h 8.2 (Berkeley) 1/4/94 */ +#include <kvm.h> + /* What is the max length of a pointer printed with %p (including 0x)? */ #define PLEN (LONG_BIT / 4 + 2) @@ -132,7 +134,7 @@ void nsprotopr(u_long, char *); void intpr(int, int); -void unixpr(u_long, u_long); +void unixpr(kvm_t *, u_long); void mroutepr(u_long, u_long, u_long); void mrt_stats(void); diff --git a/usr.bin/netstat/unix.c b/usr.bin/netstat/unix.c index 2a95b272499..01454785a60 100644 --- a/usr.bin/netstat/unix.c +++ b/usr.bin/netstat/unix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unix.c,v 1.20 2013/08/18 16:32:24 guenther Exp $ */ +/* $OpenBSD: unix.c,v 1.21 2013/10/22 16:40:28 guenther Exp $ */ /* $NetBSD: unix.c,v 1.13 1995/10/03 21:42:48 thorpej Exp $ */ /*- @@ -42,9 +42,8 @@ #include <sys/un.h> #include <sys/unpcb.h> #define _KERNEL -struct uio; -struct proc; #include <sys/file.h> +#undef _KERNEL #include <netinet/in.h> @@ -54,65 +53,42 @@ struct proc; #include <kvm.h> #include "netstat.h" -static void unixdomainpr(struct socket *, caddr_t, u_long); - -static struct file *file, *fileNFILE; -static int fcnt; -extern kvm_t *kvmd; +static void unixdomainpr(const struct kinfo_file *, u_long); void -unixpr(u_long off, u_long pcbaddr) +unixpr(kvm_t *kvmd, u_long pcbaddr) { - struct file *fp; + struct kinfo_file *kf; struct socket sock, *so = &sock; - char *filebuf; - struct protosw *unixsw = (struct protosw *)off; + int i, fcnt; - filebuf = kvm_getfiles(kvmd, KERN_FILE, 0, &fcnt); - if (filebuf == NULL) { + kf = kvm_getfiles(kvmd, KERN_FILE_BYFILE, 0, sizeof(*kf), &fcnt); + if (kf == NULL) { printf("Out of memory (file table).\n"); return; } - file = (struct file *)(filebuf + sizeof(fp)); - fileNFILE = file + fcnt; - for (fp = file; fp < fileNFILE; fp++) { - if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET) - continue; - if (kread((u_long)fp->f_data, so, sizeof (*so))) - continue; - /* kludge */ - if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2) - if (so->so_pcb) - unixdomainpr(so, fp->f_data, pcbaddr); + for (i = 0; i < fcnt; i++) { + if (kf[i].f_count != 0 && kf[i].f_type == DTYPE_SOCKET && + kf[i].so_family == AF_LOCAL && (kf[i].so_pcb != 0 || + kf[i].unp_path[0] != '\0')) + unixdomainpr(&kf[i], pcbaddr); } } -static char *socktype[] = +static const char *socktype[] = { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; static void -unixdomainpr(struct socket *so, caddr_t soaddr, u_long pcbaddr) +unixdomainpr(const struct kinfo_file *kf, u_long pcbaddr) { - struct unpcb unpcb, *unp = &unpcb; - struct mbuf mbuf, *m; - struct sockaddr_un *sa = NULL; static int first = 1; if (Pflag) { - if (pcbaddr == (u_long)soaddr) + if (pcbaddr == kf->f_data) socket_dump(pcbaddr); return; } - if (kread((u_long)so->so_pcb, unp, sizeof (*unp))) - return; - if (unp->unp_addr) { - m = &mbuf; - if (kread((u_long)unp->unp_addr, m, sizeof (*m))) - m = NULL; - sa = (struct sockaddr_un *)(m->m_dat); - } else - m = NULL; if (first) { printf("Active UNIX domain sockets\n"); printf("%-*.*s %-6.6s %-6.6s %-6.6s %*.*s %*.*s %*.*s %*.*s Addr\n", @@ -121,17 +97,17 @@ unixdomainpr(struct socket *so, caddr_t soaddr, u_long pcbaddr) PLEN, PLEN, "Refs", PLEN, PLEN, "Nextref"); first = 0; } - printf("%*p %-6.6s %6ld %6ld %*p %*p %*p %*p", - PLEN, hideroot ? 0 : soaddr, - socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc, - PLEN, hideroot ? 0 : unp->unp_vnode, - PLEN, hideroot ? 0 : unp->unp_conn, - PLEN, hideroot ? 0 : unp->unp_refs, - PLEN, hideroot ? 0 : unp->unp_nextref); - if (m) - printf(" %.*s", - (int)(m->m_len - (int)(sizeof(*sa) - sizeof(sa->sun_path))), - sa->sun_path); + +#define FAKE_PTR(p) (PLEN - ((p) ? 0 : 2)), p, ((p) ? "" : "x0") + printf("%#*llx%s %-6.6s %6ld %6ld %#*llx%s %#*llx%s %#*llx%s %#*llx%s", + FAKE_PTR(kf->f_data), socktype[kf->so_type], + kf->so_rcv_cc, kf->so_snd_cc, + FAKE_PTR(kf->v_un), + FAKE_PTR(kf->unp_conn), + FAKE_PTR(kf->unp_refs), + FAKE_PTR(kf->unp_nextref)); + if (kf->unp_path[0] != '\0') + printf(" %.*s", KI_UNPPATHLEN, kf->unp_path); putchar('\n'); } diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index ccfb8652d51..1291e68f58c 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pstat.c,v 1.86 2013/08/22 04:43:41 guenther Exp $ */ +/* $OpenBSD: pstat.c,v 1.87 2013/10/22 16:40:27 guenther Exp $ */ /* $NetBSD: pstat.c,v 1.27 1996/10/23 22:50:06 cgd Exp $ */ /*- @@ -988,7 +988,7 @@ ttyprt(struct itty *tp) void filemode(void) { - struct kinfo_file2 *kf; + struct kinfo_file *kf; char flagbuf[16], *fbp; static char *dtypes[] = { "???", "inode", "socket", "pipe", "kqueue", "crypto", "systrace" }; int mib[2], maxfile, nfile; @@ -1019,9 +1019,9 @@ filemode(void) } if (!totalflag) { - kf = kvm_getfile2(kd, KERN_FILE_BYFILE, 0, sizeof *kf, &nfile); + kf = kvm_getfiles(kd, KERN_FILE_BYFILE, 0, sizeof *kf, &nfile); if (kf == NULL) { - warnx("kvm_getfile2: %s", kvm_geterr(kd)); + warnx("kvm_getfiles: %s", kvm_geterr(kd)); return; } } |