"most interesting" process in w(1)

Yuri Pankov ypankov at fastmail.com
Tue Apr 21 21:09:51 UTC 2020


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?



More information about the freebsd-hackers mailing list