Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Oct 2017 15:09:28 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r324367 - head/bin/ps
Message-ID:  <201710061509.v96F9ScT016207@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201710061509.v96F9ScT016207>