ttymode() needs nlist, otherwise "pstat -tf" will fail since kd will not be
NULL and the calls from ttymode() to KGET will error as follows:

pstat: cannot read ntty: invalid address (0)
pstat: cannot read tty_head: invalid address (0)

KGET(TTY_NTTY, ntty) and KGET(TTY_TTYLIST, tty_head) both result in a
kvm_read() with an address (globalnl[TTY_NTTY].n_value) of zero.

The following diff resolves this issue.

Took the opportunity to reorder the flags to match the switch statement.

With help from tb@.

Rob

Index: pstat.c
===================================================================
RCS file: /cvs/src/usr.sbin/pstat/pstat.c,v
retrieving revision 1.108
diff -u -p -r1.108 pstat.c
--- pstat.c     14 Aug 2016 22:47:26 -0000      1.108
+++ pstat.c     17 Sep 2016 17:00:28 -0000
@@ -190,7 +190,7 @@ main(int argc, char *argv[])
        if ((dformat == NULL && argc > 0) || (dformat && argc == 0))
                usage();
 
-       need_nlist = vnodeflag || dformat;
+       need_nlist = dformat || (fileflag && ttyflag) || vnodeflag;
 
        if (nlistf != NULL || memf != NULL) {
                if (fileflag || totalflag)

Reply via email to