Date: Wed, 27 Jun 2001 18:26:44 -0700 From: Dima Dorfman <dima@unixfreak.org> To: Bruce Evans <bde@zeta.org.au> Cc: audit@FreeBSD.ORG Subject: Re: Patch to fix `pstat -tn` Message-ID: <20010628012644.392973E2F@bazooka.unixfreak.org> In-Reply-To: <Pine.BSF.4.21.0106171833550.99317-100000@besplex.bde.org>; from bde@zeta.org.au on "Sun, 17 Jun 2001 20:01:36 %2B1000 (EST)"
next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans <bde@zeta.org.au> writes: > On Sat, 16 Jun 2001, Dima Dorfman wrote: > > > The attached patch fixes `pstat -tn` to do what the man page says it > > should do, rather than just print '0'. I'm not sure when this was > > broken (or if it ever worked at all), but the fix is relatively > > simple. Please review. > > Lots was broken when pstat was converted to use the kern.ttys sysctl. > pstat -nt still works for ttys not returned by this sysctl. OTOH, > pstat -t is more broken for these ttys. [ snip descriptions of other cases where pstat -tn does the wrong thing ] > > > Index: pstat.c > > =================================================================== > > RCS file: /home/ncvs/src/usr.sbin/pstat/pstat.c,v > > retrieving revision 1.58 > > diff -u -c -r1.58 pstat.c > > *** pstat.c 2001/06/17 02:01:43 1.58 > > --- pstat.c 2001/06/17 02:10:19 > > *************** > > *** 854,864 **** > > int i, j; > > pid_t pgid; > > char *name, state[20]; > > > > if (usenumflag || tp->t_dev == 0 || > > ! (name = devname(tp->t_dev, S_IFCHR)) == NULL) > > ! (void)printf("%7d ", line); > > ! else > > (void)printf("%7s ", name); > > (void)printf("%2d %3d ", tp->t_rawq.c_cc, tp->t_canq.c_cc); > > (void)printf("%3d %5d %5d %4d %3d %7d ", tp->t_outq.c_cc, > > --- 854,869 ---- > > int i, j; > > pid_t pgid; > > char *name, state[20]; > > + char *tb; > > > > if (usenumflag || tp->t_dev == 0 || > > ! (name = devname(tp->t_dev, S_IFCHR)) == NULL) { > > ! i = asprintf(&tb, "%d,%d", major(tp->t_dev), minor(tp->t_dev)); > > ! if (i == -1) > > ! err(1, "asprintf"); > > ! (void)printf("%7s ", tb); > > ! free(tb); > > ! } else > > (void)printf("%7s ", name); > > (void)printf("%2d %3d ", tp->t_rawq.c_cc, tp->t_canq.c_cc); > > (void)printf("%3d %5d %5d %4d %3d %7d ", tp->t_outq.c_cc, > > I think the correct fix is just to pass the correct value for `line' > to ttyprt(). This is already done in the non-broken case (calls from > ttytype()). This is not so easy for the calls from ttymode(), since > the sysctl has lost the natural boundaries between the drivers. It seems that doing this would at least involve changing the sysctl, and I'm not sure how to do it even then. I think printing the major/minor number, as documented, is at the very least better than what we have now. The attached patch does essentially the same thing as the old one, but addressed your comments about consistency and asprintf. Suggestions? Dima Dorfman dima@unixfreak.org > > I don't like the patch for other reasons. Using asprintf() is overkill, > and the format is inconsistent. All other places in pstat.c use > " %2d,%-2d". This at least lines up the major/minor split point (the > comma) for small major/minor numbers. It misprints negative minor > numbers, but not as horribly as devname(). Large and negative minor > numbers should be printed in hex format, something like ls(1) does it. > > Note that when the major and/or minor numbers are large, all the formats > may take more than 7 characters and asprintf()'ing first doesn't help > much (unless %7.7s format is used to truncate the names). > > Bruce > Index: pstat.c =================================================================== RCS file: /stl/src/FreeBSD/src/usr.sbin/pstat/pstat.c,v retrieving revision 1.58 diff -u -r1.58 pstat.c --- pstat.c 2001/06/17 02:01:43 1.58 +++ pstat.c 2001/06/28 01:25:45 @@ -856,9 +856,10 @@ char *name, state[20]; if (usenumflag || tp->t_dev == 0 || - (name = devname(tp->t_dev, S_IFCHR)) == NULL) - (void)printf("%7d ", line); - else + (name = devname(tp->t_dev, S_IFCHR)) == NULL) { + (void)printf(" %2d,%-2d", + major(tp->t_dev), minor(tp->t_dev)); + } else (void)printf("%7s ", name); (void)printf("%2d %3d ", tp->t_rawq.c_cc, tp->t_canq.c_cc); (void)printf("%3d %5d %5d %4d %3d %7d ", tp->t_outq.c_cc, To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010628012644.392973E2F>