From ee6dd32236c275ff1a35e426e2556760c54a4c31 Mon Sep 17 00:00:00 2001 From: tjr Date: Sat, 12 Apr 2003 10:39:56 +0000 Subject: [PATCH] Display residency and sleep times (re and sl fields) larger than 127 as 127. This is what the manual page says ps should do, and what OpenBSD and NetBSD do. Based on a patch from Ken Stailey. PR: 27433, 46232 --- bin/ps/keyword.c | 4 ++-- bin/ps/print.c | 4 +++- bin/ps/ps.h | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 545694539ea8..d893d0fa67c1 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -143,7 +143,7 @@ static VAR var[] = { {"ppid", "PPID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_ppid), UINT, PIDFMT, 0}, {"pri", "PRI", NULL, 0, pri, NULL, 3, 0, CHAR, NULL, 0}, - {"re", "RE", NULL, 0, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d", + {"re", "RE", NULL, INF127, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d", 0}, {"rgid", "RGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_rgid), UINT, UIDFMT, 0}, @@ -166,7 +166,7 @@ static VAR var[] = { UINT, "x", 0}, {"sigmask", "BLOCKED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigmask), UINT, "x", 0}, - {"sl", "SL", NULL, 0, kvar, NULL, 3, KOFF(ki_slptime), UINT, "d", + {"sl", "SL", NULL, INF127, kvar, NULL, 3, KOFF(ki_slptime), UINT, "d", 0}, {"start", "STARTED", NULL, LJUST|USER, started, NULL, 7, 0, CHAR, NULL, 0}, diff --git a/bin/ps/print.c b/bin/ps/print.c index 69d33bac6a16..69fcba9a33ad 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -694,6 +694,8 @@ printval(void *bp, VAR *v) *cp++ = '*'; while ((*cp++ = *fcp++)); +#define CHKINF127(n) (((n) > 127) && (v->flag & INF127) ? 127 : (n)) + switch (v->type) { case CHAR: (void)printf(ofmt, v->width, *(char *)bp); @@ -711,7 +713,7 @@ printval(void *bp, VAR *v) (void)printf(ofmt, v->width, *(int *)bp); break; case UINT: - (void)printf(ofmt, v->width, *(u_int *)bp); + (void)printf(ofmt, v->width, CHKINF127(*(u_int *)bp)); break; case LONG: (void)printf(ofmt, v->width, *(long *)bp); diff --git a/bin/ps/ps.h b/bin/ps/ps.h index 2fd10de7c0bb..6d84697eb75e 100644 --- a/bin/ps/ps.h +++ b/bin/ps/ps.h @@ -59,6 +59,7 @@ typedef struct var { #define LJUST 0x02 /* left adjust on output (trailing blanks) */ #define USER 0x04 /* needs user structure */ #define DSIZ 0x08 /* field size is dynamic*/ +#define INF127 0x10 /* values >127 displayed as 127 */ u_int flag; /* output routine */ void (*oproc)(struct kinfo *, struct varent *);