From owner-freebsd-hackers@freebsd.org Wed Apr 22 02:44:45 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3DAB42C3769 for ; Wed, 22 Apr 2020 02:44:45 +0000 (UTC) (envelope-from kaduk@mit.edu) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 496Psl5N82z4Yy4 for ; Wed, 22 Apr 2020 02:44:43 +0000 (UTC) (envelope-from kaduk@mit.edu) Received: from kduck.mit.edu ([24.16.140.251]) (authenticated bits=56) (User authenticated as kaduk@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 03M2ibmF031417 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Apr 2020 22:44:39 -0400 Date: Tue, 21 Apr 2020 19:44:36 -0700 From: Benjamin Kaduk To: Yuri Pankov Cc: freebsd-hackers@freebsd.org Subject: Re: "most interesting" process in w(1) Message-ID: <20200422024436.GA27494@kduck.mit.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) X-Rspamd-Queue-Id: 496Psl5N82z4Yy4 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of kaduk@mit.edu designates 18.9.28.11 as permitted sender) smtp.mailfrom=kaduk@mit.edu X-Spamd-Result: default: False [-5.41 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:18.9.28.0/24]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[mit.edu]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_MED(-0.20)[11.28.9.18.list.dnswl.org : 127.0.11.2]; RCPT_COUNT_TWO(0.00)[2]; IP_SCORE(-2.91)[ip: (-9.66), ipnet: 18.9.0.0/16(-4.80), asn: 3(-0.05), country: US(-0.05)]; FREEMAIL_TO(0.00)[fastmail.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:3, ipnet:18.9.0.0/16, country:US]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Apr 2020 02:44:45 -0000 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). -Ben