Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Jan 2012 20:39:43 +0000 (UTC)
From:      Mikolaj Golub <trociny@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r230753 - head/usr.bin/procstat
Message-ID:  <201201292039.q0TKdhA7051693@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trociny
Date: Sun Jan 29 20:39:42 2012
New Revision: 230753
URL: http://svn.freebsd.org/changeset/base/230753

Log:
  Always return 0 if the sysctl failed.
  
  This fixes the bug: when procstat -xa was run and the sysctl for a
  process returned ESRCH or EPERM, for this process procstat output the
  result collected for the previous successful process.

Modified:
  head/usr.bin/procstat/procstat_auxv.c

Modified: head/usr.bin/procstat/procstat_auxv.c
==============================================================================
--- head/usr.bin/procstat/procstat_auxv.c	Sun Jan 29 19:35:40 2012	(r230752)
+++ head/usr.bin/procstat/procstat_auxv.c	Sun Jan 29 20:39:42 2012	(r230753)
@@ -81,7 +81,7 @@ is_elf32(pid_t pid)
 static size_t
 retrieve_auxv32(pid_t pid)
 {
-	int error, name[4];
+	int name[4];
 	size_t len, i;
 	void *ptr;
 
@@ -90,9 +90,9 @@ retrieve_auxv32(pid_t pid)
 	name[2] = KERN_PROC_AUXV;
 	name[3] = pid;
 	len = sizeof(auxv32);
-	error = sysctl(name, 4, auxv32, &len, NULL, 0);
-	if (error < 0 && errno != ESRCH && errno != EPERM) {
-		warn("sysctl: kern.proc.auxv: %d: %d", pid, errno);
+	if (sysctl(name, 4, auxv32, &len, NULL, 0) == -1) {
+		if (errno != ESRCH && errno != EPERM)
+			warn("sysctl: kern.proc.auxv: %d: %d", pid, errno);
 		return (0);
 	}
 	for (i = 0; i < len; i++) {
@@ -117,7 +117,7 @@ retrieve_auxv32(pid_t pid)
 static size_t
 retrieve_auxv(pid_t pid)
 {
-	int error, name[4];
+	int name[4];
 	size_t len;
 
 #if __ELF_WORD_SIZE == 64
@@ -129,9 +129,9 @@ retrieve_auxv(pid_t pid)
 	name[2] = KERN_PROC_AUXV;
 	name[3] = pid;
 	len = sizeof(auxv);
-	error = sysctl(name, 4, auxv, &len, NULL, 0);
-	if (error < 0 && errno != ESRCH && errno != EPERM) {
-		warn("sysctl: kern.proc.auxv: %d: %d", pid, errno);
+	if (sysctl(name, 4, auxv, &len, NULL, 0) == -1) {
+		if (errno != ESRCH && errno != EPERM)
+			warn("sysctl: kern.proc.auxv: %d: %d", pid, errno);
 		return (0);
 	}
 	return (len);



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