mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
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@
This commit is contained in:
parent
8c3aa3e25e
commit
6b176adcd9
@ -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},
|
||||
|
@ -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)
|
||||
|
12
bin/ps/ps.c
12
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--;
|
||||
}
|
||||
|
@ -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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user