diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2008-03-08 19:20:13 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2008-03-08 19:20:13 +0000 |
commit | 8574ef8b995918f875877c2b893eac601146a183 (patch) | |
tree | 2d3eb29556bc9b0c42fe3cd119989f47ab516841 /bin/ps | |
parent | ccc31f18930345203d46b5efd31f56e0498c43b8 (diff) |
Instead of calling donlist() in the format print routines, call it
a single time before we print anything, if needed. Uses a flag to
specify which formats need the kernel info donlist() provides.
OK deraadt@
Diffstat (limited to 'bin/ps')
-rw-r--r-- | bin/ps/keyword.c | 10 | ||||
-rw-r--r-- | bin/ps/print.c | 16 | ||||
-rw-r--r-- | bin/ps/ps.c | 12 | ||||
-rw-r--r-- | bin/ps/ps.h | 3 |
4 files changed, 21 insertions, 20 deletions
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 9da026c4cc6..6d320c5572e 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyword.c,v 1.27 2007/04/13 19:20:23 miod Exp $ */ +/* $OpenBSD: keyword.c,v 1.28 2008/03/08 19:20:12 millert Exp $ */ /* $NetBSD: keyword.c,v 1.12.6.1 1996/05/30 21:25:13 cgd Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: keyword.c,v 1.27 2007/04/13 19:20:23 miod Exp $"; +static char rcsid[] = "$OpenBSD: keyword.c,v 1.28 2008/03/08 19:20:12 millert Exp $"; #endif #endif /* not lint */ @@ -85,8 +85,8 @@ int utime(), stime(), ixrss(), idrss(), isrss(); /* Bit types must match their respective entries in struct kinfo_proc2 */ VAR var[] = { - {"%cpu", "%CPU", NULL, 0, pcpu, 4}, - {"%mem", "%MEM", NULL, 0, pmem, 4}, + {"%cpu", "%CPU", NULL, NLIST, pcpu, 4}, + {"%mem", "%MEM", NULL, NLIST, pmem, 4}, {"acflag", "ACFLG", NULL, 0, pvar, 3, 0, POFF(p_acflag), UINT16, "x"}, {"acflg", "", "acflag"}, {"args", "", "command"}, @@ -162,7 +162,7 @@ VAR var[] = { {"ssiz", "SSIZ", NULL, 0, ssize, 4}, {"start", "STARTED", NULL, LJUST|USER, started, 8}, {"stat", "", "state"}, - {"state", "STAT", NULL, LJUST, state, 5}, + {"state", "STAT", NULL, LJUST|NLIST, state, 5}, GID("svgid", "SVGID", pvar, POFF(p_svgid)), UID("svuid", "SVUID", pvar, POFF(p_svuid)), {"tdev", "TDEV", NULL, 0, tdev, 4}, diff --git a/bin/ps/print.c b/bin/ps/print.c index 05e09a3e72f..578461c87b4 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.43 2007/11/06 10:22:29 chl Exp $ */ +/* $OpenBSD: print.c,v 1.44 2008/03/08 19:20:12 millert Exp $ */ /* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; #else -static char rcsid[] = "$OpenBSD: print.c,v 1.43 2007/11/06 10:22:29 chl Exp $"; +static char rcsid[] = "$OpenBSD: print.c,v 1.44 2008/03/08 19:20:12 millert Exp $"; #endif #endif /* not lint */ @@ -64,7 +64,7 @@ static char rcsid[] = "$OpenBSD: print.c,v 1.43 2007/11/06 10:22:29 chl Exp $"; #include "ps.h" extern kvm_t *kd; -extern int needenv, needcomm, commandonly; +extern int needenv, needcomm, neednlist, commandonly; static char *cmdpart(char *); @@ -524,12 +524,9 @@ cputime(const struct kinfo_proc2 *kp, VARENT *ve) double getpcpu(const struct kinfo_proc2 *kp) { - static int failure; double d; - if (!nlistread) - failure = donlist(); - if (failure) + if (fscale == 0) return (0.0); #define fxtofl(fixpt) ((double)(fixpt) / fscale) @@ -563,13 +560,10 @@ pcpu(const struct kinfo_proc2 *kp, VARENT *ve) double getpmem(const struct kinfo_proc2 *kp) { - static int failure; double fracmem; int szptudot; - if (!nlistread) - failure = donlist(); - if (failure) + if (mempages == 0) return (0.0); if (kp->p_flag & P_SYSTEM) diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 53aa66d00f2..cfa15f804fe 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.c,v 1.44 2007/12/28 19:17:28 chl Exp $ */ +/* $OpenBSD: ps.c,v 1.45 2008/03/08 19:20:12 millert Exp $ */ /* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */ /*- @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: ps.c,v 1.44 2007/12/28 19:17:28 chl Exp $"; +static char rcsid[] = "$OpenBSD: ps.c,v 1.45 2008/03/08 19:20:12 millert Exp $"; #endif #endif /* not lint */ @@ -82,7 +82,7 @@ int totwidth; /* calculated width of requested variables */ int ncpu = 1; -int needcomm, needenv, commandonly; +int needcomm, needenv, neednlist, commandonly; enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; @@ -295,6 +295,10 @@ main(int argc, char *argv[]) * and adjusting header widths as appropriate. */ scanvars(); + + if (neednlist && !nlistread) + (void) donlist(); + /* * get proc list */ @@ -403,6 +407,8 @@ scanvars(void) totwidth += v->width + 1; /* +1 for space */ if (v->flag & COMM) needcomm = 1; + if (v->flag & NLIST) + neednlist = 1; } totwidth--; } diff --git a/bin/ps/ps.h b/bin/ps/ps.h index dc7163104e5..094444e3d6e 100644 --- a/bin/ps/ps.h +++ b/bin/ps/ps.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.h,v 1.7 2006/10/16 15:00:10 millert Exp $ */ +/* $OpenBSD: ps.h,v 1.8 2008/03/08 19:20:12 millert Exp $ */ /* $NetBSD: ps.h,v 1.11 1995/09/29 21:57:03 cgd Exp $ */ /*- @@ -60,6 +60,7 @@ typedef struct var { #define LJUST 0x02 /* left adjust on output (trailing blanks) */ #define USER 0x04 /* needs user structure */ #define INF127 0x08 /* 127 = infinity: if > 127, print 127. */ +#define NLIST 0x10 /* needs nlist info from kernel */ u_int flag; /* output routine */ void (*oproc)(const struct kinfo_proc2 *, struct varent *); |