ports/150575: Patch pcpustat to version 1.3
User Sterling Camden
sterling at camdensoftware.com
Tue Sep 14 20:20:06 UTC 2010
>Number: 150575
>Category: ports
>Synopsis: Patch pcpustat to version 1.3
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: maintainer-update
>Submitter-Id: current-users
>Arrival-Date: Tue Sep 14 20:20:05 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator: User Sterling Camden
>Release: FreeBSD 8.1-STABLE amd64
>Organization:
Camden Software Consulting
>Environment:
System: FreeBSD libertas.local.camdensoftware.com 8.1-STABLE FreeBSD 8.1-STABLE #57: Mon Sep 13 11:51:25 PDT 2010 sterling at libertas.local.camdensoftware.com:/usr/obj/usr/src/sys/LIBERTAS amd64
>Description:
Fixes another bug in determining the correct buffer size for sysctl. Doing it the right way this time (for sure).
>How-To-Repeat:
On some systems, pcpustat fails with:
pcpustat: sysctl(kern.cp_times...) expected 1280, got 160
Before outputting any data. This is due to incorrectly sizing the buffer for obtaining the sysctl value kern.cp_times.
>Fix:
The sysctlbyname(3) function provides a uniform way to obtain the proper size, so I have implemented that instead of
trying to divine the correct size based on the number of CPUs.
The tarball at http://chipstips.com/download/pcpustat-1.3.tar.bz2 has already been updated.
patches follow:
--- /usr/ports/sysutils/pcpustat/work/pcpustat-1.1/pcpustat.c 2010-07-28 08:47:43.000000000 -0700
+++ pcpustat.c 2010-09-02 13:40:42.000000000 -0700
@@ -8,7 +8,11 @@
#include <sys/resource.h>
#include <sys/sysctl.h>
-static const char* what_string="@(#)pcpustat 1.1";
+#ifndef CPUSTATES
+#define CPUSTATES 5 /* OSX doesn't define this */
+#endif
+
+static const char* what_string="@(#)pcpustat 1.3";
/* Bit flags for what stats to include: */
@@ -23,6 +27,7 @@
/* Copied from /usr/src/usr.bin/top/machine.c */
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
static void getsysctl(const char *name, void *ptr, size_t len);
+static size_t getsysctllen(const char *name);
struct opthelp {
char *argname;
@@ -31,7 +36,7 @@
int main(int ac, char **av)
{
- int c, option_index, stats=0, count=-1, wait=0, cpu, maxcpu, ncpu, quiet=0, not=0;
+ int c, option_index, stats=0, count=-1, wait=0, cpu, ncpu, quiet=0, not=0;
size_t state_size;
long cpus=0;
long *cpu_prev, *cpu_curr;
@@ -194,8 +199,7 @@
printf("\n");
}
- GETSYSCTL("kern.smp.maxcpus", maxcpu);
- state_size = CPUSTATES * maxcpu * sizeof(long);
+ state_size = getsysctllen("kern.cp_times");
cpu_prev = malloc(state_size);
cpu_curr = malloc(state_size);
getsysctl("kern.cp_times", cpu_prev, state_size);
@@ -253,9 +257,16 @@
sys_errlist[errno]);
exit(23);
}
- if (nlen != len) {
- fprintf(stderr, "pcpustat: sysctl(%s...) expected %lu, got %lu\n",
- name, (unsigned long)len, (unsigned long)nlen);
+}
+
+static size_t
+getsysctllen(const char *name)
+{
+ size_t len = 0;
+ if (sysctlbyname(name, NULL, &len, NULL, 0) == -1) {
+ fprintf(stderr, "pcpustat: sysctl(%s...) failed: %s\n", name,
+ sys_errlist[errno]);
exit(23);
}
+ return len;
}
--- /usr/ports/sysutils/pcpustat/Makefile 2010-09-14 10:13:36.000000000 -0700
+++ port/Makefile.new 2010-09-14 10:12:45.000000000 -0700
@@ -6,7 +6,7 @@
#
PORTNAME= pcpustat
-PORTVERSION= 1.1
+PORTVERSION= 1.3
CATEGORIES= sysutils
MASTER_SITES= http://chipstips.com/download/
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list