svn commit: r324367 - head/bin/ps

Edward Tomasz Napierala trasz at FreeBSD.org
Fri Oct 6 15:09:29 UTC 2017


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) {


More information about the svn-src-all mailing list