Subject: bin/11653: ps -O ktracep,nwchan,p_ru,paddr,rlink,sess,tsess is broken
To: None <gnats-bugs@gnats.netbsd.org>
From: None <minoura@netbsd.org>
List: netbsd-bugs
Date: 12/06/2000 19:05:16
>Number:         11653
>Category:       bin
>Synopsis:       ps -O ktracep,nwchan,p_ru,paddr,rlink,sess,tsess is broken
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 06 19:05:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Minoura Makoto
>Release:        -current, 20001126
>Organization:
	The NetBSD Project / hauN.ORG
>Environment:
System: NetBSD donald 1.5L NetBSD 1.5L (TOKOCHAN) #4: Wed Dec 6 22:04:18 JST 2000 root@chip:/usr/obj/sys/arch/x68k/compile/TOKOCHAN x68k
Architecture: m68k
Machine: x68k
>Description:
Some information of ps(1) is displayed as 0 on big-endian machines.
Also on alphas the output is completely wrong.

> minoura@donald(102)% ps -O ktracep,nwchan,p_ru,paddr,rlink,sess,tsess       [~]
> PID KTRACEP WCHAN P_RU PADDR RLINK SESS TSESS TT STAT    TIME COMMAND
> 263       0     0    0     0     0    0     0 p0 Ss   0:07.89 -tcsh 
> 282       0     0    0     0     0    0     0 p0 TW   0:00.00 /bin/sh /usr/bin/
> 332       0     0    0     0     0    0     0 p0 T    0:08.53 nvi /tmp/p282 
> 336       0     0    0     0     0    0     0 p0 R+   0:00.11 ps -O ktracep

This is because ps(1) treats the pointers as ulong, although the
systemcall returns 64bit values.

>How-To-Repeat:
See above.

>Fix:
Not a `nice' fix but (I believe) works on all supported archs.
Systemcall returns u_int64_t values, but the ps(1) reads them
as u_longlong_t.

Tested on x68k and alpha.

Index: keyword.c
===================================================================
RCS file: /proj/cvsroot/netbsd/src/bin/ps/keyword.c,v
retrieving revision 1.1.1.6
diff -u -r1.1.1.6 keyword.c
--- keyword.c	2000/06/11 11:05:31	1.1.1.6
+++ keyword.c	2000/12/05 10:48:56
@@ -102,7 +102,7 @@
 	{"jobc", "JOBC", NULL, 0, pvar, 0, POFF(p_jobc), SHORT, "d"},
 	{"ktrace", "KTRACE", NULL, 0, pvar, 0, POFF(p_traceflag), INT, "x"},
 	/* XXX */
-	{"ktracep", "KTRACEP", NULL, 0, pvar, 0, POFF(p_tracep), KPTR, "x"},
+	{"ktracep", "KTRACEP", NULL, 0, pvar, 0, POFF(p_tracep), KPTR, "llx"},
 	{"lim", "LIM", NULL, 0, maxrss},
 	{"login", "LOGIN", NULL, LJUST, logname},
 	{"logname", "", "login"},
@@ -119,13 +119,13 @@
 	{"nswap", "NSWAP", NULL, 0, pvar, 0, POFF(p_uru_nswap), ULONG, "d"},
 	{"nvcsw", "NVCSW", NULL, 0, pvar, 0, POFF(p_uru_nvcsw), ULONG, "d"},
 	/* XXX */
-	{"nwchan", "WCHAN", NULL, 0, pvar, 0, POFF(p_wchan), KPTR, "x"},
+	{"nwchan", "WCHAN", NULL, 0, pvar, 0, POFF(p_wchan), KPTR, "llx"},
 	{"oublk", "OUBLK", NULL, 0, pvar, 0, POFF(p_uru_oublock), ULONG, "d"},
 	{"oublock", "", "oublk"},
 	/* XXX */
-	{"p_ru", "P_RU", NULL, 0, pvar, 0, POFF(p_ru), KPTR, "x"},
+	{"p_ru", "P_RU", NULL, 0, pvar, 0, POFF(p_ru), KPTR, "llx"},
 	/* XXX */
-	{"paddr", "PADDR", NULL, 0, pvar, 0, POFF(p_paddr), KPTR, "x"},
+	{"paddr", "PADDR", NULL, 0, pvar, 0, POFF(p_paddr), KPTR, "llx"},
 	{"pagein", "PAGEIN", NULL, 0, pagein},
 	{"pcpu", "", "%cpu"},
 	{"pending", "", "sig"},
@@ -137,13 +137,13 @@
 	{"re", "RE", NULL, INF127, pvar, 0, POFF(p_swtime), UINT, "d"},
 	GID("rgid", "RGID", pvar, POFF(p_rgid)),
 	/* XXX */
-	{"rlink", "RLINK", NULL, 0, pvar, 0, POFF(p_back), KPTR, "x"},
+	{"rlink", "RLINK", NULL, 0, pvar, 0, POFF(p_back), KPTR, "llx"},
 	{"rss", "RSS", NULL, 0, p_rssize},
 	{"rssize", "", "rsz"},
 	{"rsz", "RSZ", NULL, 0, rssize},
 	UID("ruid", "RUID", pvar, POFF(p_ruid)),
 	{"ruser", "RUSER", NULL, LJUST, runame},
-	{"sess", "SESS", NULL, 0, pvar, 0, POFF(p_sess), KPTR24, "x"},
+	{"sess", "SESS", NULL, 0, pvar, 0, POFF(p_sess), KPTR24, "llx"},
 	PID("sid", "SID", pvar, POFF(p_sid)),
 	{"sig", "PENDING",
 	    NULL, 0, pvar, 0, POFF(p_siglist), SIGLIST, "s"},
@@ -162,7 +162,7 @@
 	{"tdev", "TDEV", NULL, 0, tdev},
 	{"time", "TIME", NULL, 0, cputime},
 	PID("tpgid", "TGPID", pvar, POFF(p_tpgid)),
-	{"tsess", "TSESS", NULL, 0, pvar, 0, POFF(p_tsess), KPTR, "x"},
+	{"tsess", "TSESS", NULL, 0, pvar, 0, POFF(p_tsess), KPTR, "llx"},
 	{"tsiz", "TSIZ", NULL, 0, tsize},
 	{"tt", "TT", NULL, LJUST, tname},
 	{"tty", "TTY", NULL, LJUST, longtname},
Index: print.c
===================================================================
RCS file: /proj/cvsroot/netbsd/src/bin/ps/print.c,v
retrieving revision 1.1.1.6
diff -u -r1.1.1.6 print.c
--- print.c	2000/06/11 11:05:40	1.1.1.6
+++ print.c	2000/12/05 10:47:20
@@ -929,11 +929,11 @@
 			vok = VUNSIGN;
 			break;
 		case KPTR:
-			uval = GET(u_long);
+			uval = GET(u_longlong_t);
 			vok = VPTR;
 			break;
 		case KPTR24:
-			uval = GET(u_long) & 0xffffff;
+			uval = GET(u_longlong_t) & 0xffffff;
 			vok = VPTR;
 			break;
 		default:
@@ -1029,10 +1029,10 @@
 		(void)printf(ofmt, width, CHK_INF127(GET(u_long)));
 		return;
 	case KPTR:
-		(void)printf(ofmt, width, GET(u_long));
+		(void)printf(ofmt, width, GET(u_longlong_t));
 		return;
 	case KPTR24:
-		(void)printf(ofmt, width, GET(u_long) & 0xffffff);
+		(void)printf(ofmt, width, GET(u_longlong_t) & 0xffffff);
 		return;
 	case SIGLIST:
 		{
>Release-Note:
>Audit-Trail:
>Unformatted: