diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-01-08 19:28:57 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-01-08 19:28:57 +0000 |
commit | 16775a74a7ec3bf99ad7a9c1fb34869220bbdefd (patch) | |
tree | 7348e194a93fafc39be12b3bc06ea738f396e081 /usr.bin | |
parent | c7d844d35a263bd61cc16ec2de41ebb9e219a6aa (diff) |
Convert to kvm_getproc2(); ok deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/fstat/fstat.c | 34 | ||||
-rw-r--r-- | usr.bin/systat/pigs.c | 33 |
2 files changed, 31 insertions, 36 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 7fe7bf37b77..5a1abf2ecf4 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fstat.c,v 1.48 2003/09/09 04:46:44 jmc Exp $ */ +/* $OpenBSD: fstat.c,v 1.49 2004/01/08 19:28:56 millert Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -37,7 +37,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$OpenBSD: fstat.c,v 1.48 2003/09/09 04:46:44 jmc Exp $"; +static char *rcsid = "$OpenBSD: fstat.c,v 1.49 2004/01/08 19:28:56 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -152,7 +152,7 @@ int msdos_filestat(struct vnode *, struct filestat *); int nfs_filestat(struct vnode *, struct filestat *); int xfs_filestat(struct vnode *, struct filestat *); int null_filestat(struct vnode *, struct filestat *); -void dofiles(struct kinfo_proc *); +void dofiles(struct kinfo_proc2 *); void getinetproto(int); void socktrans(struct socket *, int); void usage(void); @@ -171,7 +171,7 @@ main(int argc, char *argv[]) extern char *optarg; extern int optind; struct passwd *passwd; - struct kinfo_proc *p, *plast; + struct kinfo_proc2 *p, *plast; int arg, ch, what; char *memf, *nlistf; char buf[_POSIX2_LINE_MAX]; @@ -256,7 +256,7 @@ main(int argc, char *argv[]) checkfile = 1; } - if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) + if ((p = kvm_getproc2(kd, what, arg, sizeof(*p), &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); if (nflg) printf("%s", @@ -272,7 +272,7 @@ main(int argc, char *argv[]) putchar('\n'); for (plast = &p[cnt]; p < plast; ++p) { - if (p->kp_proc.p_stat == SZOMB) + if (p->p_stat == SZOMB) continue; dofiles(p); } @@ -307,30 +307,28 @@ pid_t Pid; * print open files attributed to this process */ void -dofiles(struct kinfo_proc *kp) +dofiles(struct kinfo_proc2 *kp) { int i; struct file file; struct filedesc0 filed0; #define filed filed0.fd_fd - struct proc *p = &kp->kp_proc; - struct eproc *ep = &kp->kp_eproc; - Uname = user_from_uid(ep->e_ucred.cr_uid, 0); - Pid = p->p_pid; - Comm = p->p_comm; + Uname = user_from_uid(kp->p_uid, 0); + Pid = kp->p_pid; + Comm = kp->p_comm; - if (p->p_fd == NULL) + if (kp->p_fd == 0) return; - if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) { + if (!KVM_READ(kp->p_fd, &filed0, sizeof (filed0))) { dprintf("can't read filedesc at %p for pid %ld", - p->p_fd, (long)Pid); + (void *)(u_long)kp->p_fd, (long)Pid); return; } if (filed.fd_nfiles < 0 || filed.fd_lastfile >= filed.fd_nfiles || filed.fd_freefile > filed.fd_lastfile + 1) { dprintf("filedesc corrupted at %p for pid %ld", - p->p_fd, (long)Pid); + (void *)(u_long)kp->p_fd, (long)Pid); return; } /* @@ -345,8 +343,8 @@ dofiles(struct kinfo_proc *kp) /* * ktrace vnode, if one */ - if (p->p_tracep) - vtrans(p->p_tracep, TRACE, FREAD|FWRITE, 0); + if (kp->p_tracep) + vtrans((struct vnode *)(u_long)kp->p_tracep, TRACE, FREAD|FWRITE, 0); /* * open files */ diff --git a/usr.bin/systat/pigs.c b/usr.bin/systat/pigs.c index 4c47051e9f2..6455290a58d 100644 --- a/usr.bin/systat/pigs.c +++ b/usr.bin/systat/pigs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pigs.c,v 1.15 2003/06/03 02:56:17 millert Exp $ */ +/* $OpenBSD: pigs.c,v 1.16 2004/01/08 19:28:56 millert Exp $ */ /* $NetBSD: pigs.c,v 1.3 1995/04/29 05:54:50 cgd Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)pigs.c 8.2 (Berkeley) 9/23/93"; #endif -static char rcsid[] = "$OpenBSD: pigs.c,v 1.15 2003/06/03 02:56:17 millert Exp $"; +static char rcsid[] = "$OpenBSD: pigs.c,v 1.16 2004/01/08 19:28:56 millert Exp $"; #endif /* not lint */ /* @@ -64,7 +64,7 @@ int compar(const void *, const void *); static int nproc; static struct p_times { float pt_pctcpu; - struct kinfo_proc *pt_kp; + struct kinfo_proc2 *pt_kp; } *pt; static long stime[CPUSTATES]; @@ -91,7 +91,7 @@ void showpigs(void) { int i, j, y, k; - struct eproc *ep; + struct kinfo_proc2 *kp; float total; int factor; char *uname, *pname, pidname[30]; @@ -115,13 +115,13 @@ showpigs(void) if (i > wnd->_maxy-1) i = wnd->_maxy-1; for (k = 0; i > 0 && pt[k].pt_pctcpu > 0.01; i--, y++, k++) { - if (pt[k].pt_kp == NULL) { + kp = pt[k].pt_kp; + if (kp == NULL) { uname = ""; pname = "<idle>"; } else { - ep = &pt[k].pt_kp->kp_eproc; - uname = user_from_uid(ep->e_ucred.cr_uid, 0); - pname = pt[k].pt_kp->kp_proc.p_comm; + uname = user_from_uid(kp->p_uid, 0); + pname = kp->p_comm; } wmove(wnd, y, 0); wclrtoeol(wnd); @@ -165,16 +165,15 @@ fetchpigs(void) { static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; static int lastnproc = 0; - struct kinfo_proc *kpp; + struct kinfo_proc2 *kpp; long ctime[CPUSTATES]; - float time; double t; int i; size_t size; - struct proc *pp; - float *pctp; + float *pctp;; - if ((kpp = kvm_getprocs(kd, KERN_PROC_KTHREAD, 0, &nproc)) == NULL) { + kpp = kvm_getproc2(kd, KERN_PROC_KTHREAD, 0, sizeof(*kpp), &nproc); + if (kpp == NULL) { error("%s", kvm_geterr(kd)); if (pt) free(pt); @@ -194,14 +193,12 @@ fetchpigs(void) */ for (i = 0; i < nproc; i++) { pt[i].pt_kp = &kpp[i]; - pp = &kpp[i].kp_proc; pctp = &pt[i].pt_pctcpu; - time = pp->p_swtime; - if (time == 0 || (pp->p_flag & P_INMEM) == 0) + if (kpp->p_swtime == 0 || (kpp->p_flag & P_INMEM) == 0) *pctp = 0; else - *pctp = ((double) pp->p_pctcpu / - sysload.fscale) / (1.0 - exp(time * lccpu)); + *pctp = ((double) kpp->p_pctcpu / sysload.fscale) / + (1.0 - exp(kpp->p_swtime * lccpu)); } /* * and for the imaginary "idle" process |