Date: Wed, 22 Apr 2020 06:03:11 +0300 From: Yuri Pankov <ypankov@fastmail.com> To: Benjamin Kaduk <kaduk@mit.edu> Cc: freebsd-hackers@freebsd.org Subject: Re: "most interesting" process in w(1) Message-ID: <a4199844-36a6-6274-dfe3-84bddad45652@fastmail.com> In-Reply-To: <20200422024436.GA27494@kduck.mit.edu> References: <b43e40b2-c2a0-cf55-a932-ab2e0cefdcdb@fastmail.com> <20200422024436.GA27494@kduck.mit.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
Benjamin Kaduk wrote: > On Wed, Apr 22, 2020 at 12:09:48AM +0300, Yuri Pankov wrote: >> Looking at how w(1) finds "most interesting" process for terminal, I >> noticed the following code which looks strange to me (usr.bin/w/w.c, >> line 360 in HEAD) >> >> for (ep = ehead; ep != NULL; ep = ep->next) { >> if (ep->tdev == kp->ki_tdev) { >> /* >> * proc is associated with this terminal >> */ >> if (ep->kp == NULL && kp->ki_pgid == kp->ki_tpgid) { >> /* >> * Proc is 'most interesting' >> */ >> if (proc_compare(ep->kp, kp)) >> ep->kp = kp; >> ... >> } >> } >> } >> >> Given the (ep->kp == NULL) check, proc_compare() becomes no-op, it will >> always select kp, and that's the only place we ever set ep->kp, so the >> first matching process is always "most interesting". If that's really >> what we want, we could do without the proc_compare() call. What am I >> missing here? > > I suspect it makes more sense as a "!=" than a "==" (with ep->kp = kp; > always occurring for the "== NULL" case). (ep->kp == NULL) check seems to be unrelated addition in r29310 (!), the code around it gives no hints on why it was added.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a4199844-36a6-6274-dfe3-84bddad45652>