From owner-svn-src-head@freebsd.org Fri Oct 6 15:09:29 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A0BD8E39623; Fri, 6 Oct 2017 15:09:29 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (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 6AF103279; Fri, 6 Oct 2017 15:09:29 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v96F9Suf016208; Fri, 6 Oct 2017 15:09:28 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v96F9ScT016207; Fri, 6 Oct 2017 15:09:28 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201710061509.v96F9ScT016207@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Fri, 6 Oct 2017 15:09:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324367 - head/bin/ps X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/bin/ps X-SVN-Commit-Revision: 324367 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Oct 2017 15:09:29 -0000 Author: trasz Date: Fri Oct 6 15:09:28 2017 New Revision: 324367 URL: https://svnweb.freebsd.org/changeset/base/324367 Log: Fix kvm_getprocs(3) error reporting in ps(1). Previously it just didn't work at all - kvm_getprocs(3) doesn't update the &nentries when it returns NULL. The end result was that ps(1) showed garbage data instead of reporting kinfo_proc size mismatch. Reviewed by: cem Obtained from: CheriBSD MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D12414 Modified: head/bin/ps/ps.c Modified: head/bin/ps/ps.c ============================================================================== --- head/bin/ps/ps.c Fri Oct 6 14:29:53 2017 (r324366) +++ head/bin/ps/ps.c Fri Oct 6 15:09:28 2017 (r324367) @@ -523,7 +523,11 @@ main(int argc, char *argv[]) */ nentries = -1; kp = kvm_getprocs(kd, what, flag, &nentries); - if ((kp == NULL && nentries > 0) || (kp != NULL && nentries < 0)) + /* + * Ignore ESRCH to preserve behaviour of "ps -p nonexistent-pid" + * not reporting an error. + */ + if ((kp == NULL && errno != ESRCH) || (kp != NULL && nentries < 0)) xo_errx(1, "%s", kvm_geterr(kd)); nkept = 0; if (nentries > 0) {