diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-01-07 05:38:13 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-01-07 05:38:13 +0000 |
commit | 9c22654341479292c2a155db5eff66302470f976 (patch) | |
tree | 63408cc0f48f4f1d3e63b5d6a2aafd56590dc9c6 /lib | |
parent | a279f2f3d85c99cdfafe036c75959e20e475e29d (diff) |
Add rtable id and thread id to struct kinfo_proc (and fix process id)
and add an 'rtableid' keyword to ps.
Add rtable id, thread id, and socket splice info to struct kinfo_file2
and make fstat display socket splice information.
Remove old KVM_PROC2 and kinfo_proc2 interfaces; bump libkvm major
Socket splice info and corrections from bluhm@ "Lovely" deraadt@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libkvm/Makefile | 4 | ||||
-rw-r--r-- | lib/libkvm/kvm_file2.c | 43 | ||||
-rw-r--r-- | lib/libkvm/kvm_getprocs.3 | 32 | ||||
-rw-r--r-- | lib/libkvm/kvm_proc.c | 14 | ||||
-rw-r--r-- | lib/libkvm/kvm_proc2.c | 23 | ||||
-rw-r--r-- | lib/libkvm/shlib_version | 2 |
6 files changed, 53 insertions, 65 deletions
diff --git a/lib/libkvm/Makefile b/lib/libkvm/Makefile index 1debf0ff158..c56049c3f1d 100644 --- a/lib/libkvm/Makefile +++ b/lib/libkvm/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.14 2010/02/03 20:49:00 miod Exp $ +# $OpenBSD: Makefile,v 1.15 2012/01/07 05:38:12 guenther Exp $ # $NetBSD: Makefile,v 1.11 1996/03/18 22:33:07 thorpej Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/4/93 @@ -27,8 +27,6 @@ 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_getprocs.3 kvm_getproc2.3 -MLINKS+=kvm_getprocs.3 kvm_getargv2.3 kvm_getprocs.3 kvm_getenvv2.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 diff --git a/lib/libkvm/kvm_file2.c b/lib/libkvm/kvm_file2.c index b39d85443fb..37b8485b883 100644 --- a/lib/libkvm/kvm_file2.c +++ b/lib/libkvm/kvm_file2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_file2.c,v 1.18 2011/12/14 17:33:46 guenther Exp $ */ +/* $OpenBSD: kvm_file2.c,v 1.19 2012/01/07 05:38:12 guenther Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -119,7 +119,7 @@ static struct kinfo_file2 *kvm_deadfile2_byfile(kvm_t *, int, int, static struct kinfo_file2 *kvm_deadfile2_byid(kvm_t *, int, int, size_t, int *); static int fill_file2(kvm_t *, struct kinfo_file2 *, struct file *, - struct vnode *, struct proc *, int); + struct vnode *, struct proc *, int, pid_t); static int filestat(kvm_t *, struct kinfo_file2 *, struct vnode *); LIST_HEAD(proclist, proc); @@ -242,7 +242,7 @@ kvm_deadfile2_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt) where += sizeof(struct kinfo_file2); buflen -= sizeof(struct kinfo_file2); n++; - if (fill_file2(kd, kf, fp, NULL, NULL, 0) == -1) + if (fill_file2(kd, kf, fp, NULL, NULL, 0, 0) == -1) return (NULL); } if (n != nfiles) { @@ -266,11 +266,12 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) struct filedesc0 filed0; #define filed filed0.fd_fd struct proclist allproc; - struct proc *p, proc; + struct proc *p, proc, proc2; struct process process; struct pcred pcred; struct ucred ucred; int i, nfiles, nprocs; + pid_t pid; nl[0].n_name = "_filehead"; nl[1].n_name = "_nfiles"; @@ -341,6 +342,17 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) return (NULL); } proc.p_p = &process; + if ((proc.p_flag & P_THREAD) == 0) + pid = proc.p_pid; + else { + if (KREAD(kd, (u_long)process.ps_mainproc, &proc2)) { + _kvm_err(kd, kd->program, + "can't read proc at %x", + process.ps_mainproc); + return (NULL); + } + pid = proc2.p_pid; + } if (KREAD(kd, (u_long)process.ps_cred, &pcred) == 0) KREAD(kd, (u_long)pcred.pc_ucred, &ucred); @@ -362,7 +374,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) buflen -= sizeof(struct kinfo_file2); n++; if (fill_file2(kd, kf, NULL, proc.p_textvp, &proc, - KERN_FILE_TEXT) == -1) + KERN_FILE_TEXT, pid) == -1) return (NULL); } if (filed.fd_cdir) { @@ -373,7 +385,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) buflen -= sizeof(struct kinfo_file2); n++; if (fill_file2(kd, kf, NULL, filed.fd_cdir, &proc, - KERN_FILE_CDIR) == -1) + KERN_FILE_CDIR, pid) == -1) return (NULL); } if (filed.fd_rdir) { @@ -384,7 +396,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) buflen -= sizeof(struct kinfo_file2); n++; if (fill_file2(kd, kf, NULL, filed.fd_rdir, &proc, - KERN_FILE_RDIR) == -1) + KERN_FILE_RDIR, pid) == -1) return (NULL); } if (process.ps_tracevp) { @@ -395,7 +407,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) buflen -= sizeof(struct kinfo_file2); n++; if (fill_file2(kd, kf, NULL, process.ps_tracevp, &proc, - KERN_FILE_TRACE) == -1) + KERN_FILE_TRACE, pid) == -1) return (NULL); } @@ -421,7 +433,8 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) where += sizeof(struct kinfo_file2); buflen -= sizeof(struct kinfo_file2); n++; - if (fill_file2(kd, kf, &file, NULL, &proc, i) == -1) + if (fill_file2(kd, kf, &file, NULL, &proc, i, pid) + == -1) return (NULL); } } @@ -432,7 +445,7 @@ done: static int fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, struct vnode *vp, - struct proc *p, int fd) + struct proc *p, int fd, pid_t pid) { struct ucred f_cred; @@ -532,6 +545,11 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, struct vnode *vp, return (-1); } kf->so_family = domain.dom_family; + if (sock.so_splice) { + kf->so_splice = PTRTOINT64(sock.so_splice); + kf->so_splicelen = sock.so_splicelen; + } else if (sock.so_spliceback) + kf->so_splicelen = -1; if (!sock.so_pcb) break; switch (kf->so_family) { @@ -547,6 +565,7 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, struct vnode *vp, kf->inp_laddru[0] = inpcb.inp_laddr.s_addr; kf->inp_fport = inpcb.inp_fport; kf->inp_faddru[0] = inpcb.inp_faddr.s_addr; + kf->inp_rtableid = inpcb.inp_rtableid; break; } case AF_INET6: { @@ -568,6 +587,7 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, struct vnode *vp, kf->inp_faddru[1] = inpcb.inp_faddr6.s6_addr32[1]; kf->inp_faddru[2] = inpcb.inp_faddr6.s6_addr32[2]; kf->inp_faddru[3] = inpcb.inp_faddr6.s6_addr32[3]; + kf->inp_rtableid = inpcb.inp_rtableid; break; } case AF_UNIX: { @@ -621,9 +641,10 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, struct vnode *vp, /* per-process information for KERN_FILE_BY[PU]ID */ if (p != NULL) { - kf->p_pid = p->p_pid; + kf->p_pid = pid; kf->p_uid = p->p_ucred->cr_uid; kf->p_gid = p->p_ucred->cr_gid; + kf->p_tid = p->p_pid + THREAD_PID_OFFSET; strlcpy(kf->p_comm, p->p_comm, sizeof(kf->p_comm)); if (p->p_fd != NULL) kf->fd_ofileflags = p->p_fd->fd_ofileflags[fd]; diff --git a/lib/libkvm/kvm_getprocs.3 b/lib/libkvm/kvm_getprocs.3 index cf1a0b69189..e2acf477b22 100644 --- a/lib/libkvm/kvm_getprocs.3 +++ b/lib/libkvm/kvm_getprocs.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kvm_getprocs.3,v 1.16 2011/08/18 13:01:26 jmc Exp $ +.\" $OpenBSD: kvm_getprocs.3,v 1.17 2012/01/07 05:38:12 guenther Exp $ .\" $NetBSD: kvm_getprocs.3,v 1.13 2003/08/07 16:44:37 agc Exp $ .\" .\" Copyright (c) 1992, 1993 @@ -34,16 +34,13 @@ .\" .\" @(#)kvm_getprocs.3 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: August 18 2011 $ +.Dd $Mdocdate: January 7 2012 $ .Dt KVM_GETPROCS 3 .Os .Sh NAME .Nm kvm_getprocs , .Nm kvm_getargv , -.Nm kvm_getenvv , -.Nm kvm_getproc2 , -.Nm kvm_getargv2 , -.Nm kvm_getenvv2 +.Nm kvm_getenvv .Nd access user process state .Sh SYNOPSIS .Fd #include <sys/param.h> @@ -55,12 +52,6 @@ .Fn kvm_getargv "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" .Ft char ** .Fn kvm_getenvv "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" -.Ft struct kinfo_proc * -.Fn kvm_getproc2 "kvm_t *kd" "int op" "int arg" "size_t elemsize" "int *cnt" -.Ft char ** -.Fn kvm_getargv2 "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" -.Ft char ** -.Fn kvm_getenvv2 "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" .Sh DESCRIPTION .Fn kvm_getprocs returns a (sub-)set of active processes in the kernel indicated by @@ -172,26 +163,11 @@ function is similar to .Fn kvm_getargv but returns the vector of environment strings. This data is also alterable by the process. -.Pp -The -.Fn kvm_getproc2 , -.Fn kvm_getargv2 , -and -.Fn kvm_getenvv2 -functions are obsolete equivalents for -.Fn kvm_getprocs , -.Fn kvm_getargv , -and -.Fn kvm_getenvv -and have identical signatures and behavior. .Sh RETURN VALUES .Fn kvm_getprocs , .Fn kvm_getargv , -.Fn kvm_getenvv , -.Fn kvm_getproc2 , -.Fn kvm_getargv2 , and -.Fn kvm_getenvv2 +.Fn kvm_getenvv all return .Dv NULL on failure. diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index 57be5c1b731..8bc0745b638 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc.c,v 1.44 2011/06/06 17:18:26 ariane Exp $ */ +/* $OpenBSD: kvm_proc.c,v 1.45 2012/01/07 05:38:12 guenther Exp $ */ /* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -474,12 +474,6 @@ kvm_getargv(kvm_t *kd, const struct kinfo_proc *kp, int nchr) } char ** -kvm_getargv2(kvm_t *kd, const struct kinfo_proc *kp, int nchr) -{ - return (kvm_getargv(kd, kp, nchr)); -} - -char ** kvm_getenvv(kvm_t *kd, const struct kinfo_proc *kp, int nchr) { struct miniproc p; @@ -490,12 +484,6 @@ kvm_getenvv(kvm_t *kd, const struct kinfo_proc *kp, int nchr) return (kvm_doargv(kd, &p, nchr, ps_str_e)); } -char ** -kvm_getenvv2(kvm_t *kd, const struct kinfo_proc *kp, int nchr) -{ - return (kvm_getenvv(kd, kp, nchr)); -} - /* * Read from user space. The user context is given by p. */ diff --git a/lib/libkvm/kvm_proc2.c b/lib/libkvm/kvm_proc2.c index 33052b3e6e8..f98c7db2ebc 100644 --- a/lib/libkvm/kvm_proc2.c +++ b/lib/libkvm/kvm_proc2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc2.c,v 1.8 2011/07/05 04:48:01 guenther Exp $ */ +/* $OpenBSD: kvm_proc2.c,v 1.9 2012/01/07 05:38:12 guenther Exp $ */ /* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -118,7 +118,7 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, struct vmspace vm, *vmp; struct plimit limits, *limp; struct pstats pstats, *ps; - pid_t parent_pid, leader_pid; + pid_t process_pid, parent_pid, leader_pid; int cnt = 0; for (; cnt < maxcnt && p != NULL; p = LIST_NEXT(&proc, p_list)) { @@ -136,6 +136,17 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, process.ps_cred); return (-1); } + if ((proc.p_flag & P_THREAD) == 0) + process_pid = proc.p_pid; + else { + if (KREAD(kd, (u_long)process.ps_mainproc, &proc2)) { + _kvm_err(kd, kd->program, + "can't read proc at %x", + process.ps_mainproc); + return (-1); + } + process_pid = proc2.p_pid; + } if (KREAD(kd, (u_long)pcred.pc_ucred, &ucred)) { _kvm_err(kd, kd->program, "can't read ucred at %x", pcred.pc_ucred); @@ -282,6 +293,7 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, #undef do_copy_str /* stuff that's too painful to generalize into the macros */ + kp.p_pid = process_pid; kp.p_ppid = parent_pid; kp.p_sid = leader_pid; if ((process.ps_flags & PS_CONTROLT) && sess.s_ttyp != NULL) { @@ -406,10 +418,3 @@ kvm_getprocs(kvm_t *kd, int op, int arg, size_t esize, int *cnt) *cnt = nprocs; return (kd->procbase); } - -struct kinfo_proc * -kvm_getproc2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) -{ - return (kvm_getprocs(kd, op, arg, esize, cnt)); -} - diff --git a/lib/libkvm/shlib_version b/lib/libkvm/shlib_version index f461c533903..56246d02b24 100644 --- a/lib/libkvm/shlib_version +++ b/lib/libkvm/shlib_version @@ -1,2 +1,2 @@ -major=11 +major=12 minor=0 |