svn commit: r325820 - stable/11/bin/ps

Edward Tomasz Napierala trasz at FreeBSD.org
Tue Nov 14 17:57:49 UTC 2017


Author: trasz
Date: Tue Nov 14 17:57:48 2017
New Revision: 325820
URL: https://svnweb.freebsd.org/changeset/base/325820

Log:
  MFC r324367:
  
  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.

Modified:
  stable/11/bin/ps/ps.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/ps/ps.c
==============================================================================
--- stable/11/bin/ps/ps.c	Tue Nov 14 17:56:32 2017	(r325819)
+++ stable/11/bin/ps/ps.c	Tue Nov 14 17:57:48 2017	(r325820)
@@ -521,7 +521,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