Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Nov 2017 17:57:48 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r325820 - stable/11/bin/ps
Message-ID:  <201711141757.vAEHvmah068978@repo.freebsd.org>

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



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