aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/xfce4-cpugraph-plugin
diff options
context:
space:
mode:
authorrene <rene@FreeBSD.org>2012-01-01 00:40:53 +0800
committerrene <rene@FreeBSD.org>2012-01-01 00:40:53 +0800
commitdfb3ddc3a59cb254355abfed5893dc4248aae42d (patch)
tree733ed6d46db315426bf619867ec764b3d20ea686 /sysutils/xfce4-cpugraph-plugin
parent7465f5b833800af374540bc294259192a4ca619c (diff)
downloadfreebsd-ports-gnome-dfb3ddc3a59cb254355abfed5893dc4248aae42d.tar.gz
freebsd-ports-gnome-dfb3ddc3a59cb254355abfed5893dc4248aae42d.tar.zst
freebsd-ports-gnome-dfb3ddc3a59cb254355abfed5893dc4248aae42d.zip
- Fix the situation where kern.smp.maxid > hw.ncpu by using the former value,
otherwise this would lead to insufficient space for the kern.cp_times sysctlbyname() call. [1] - Bump PORTREVISION Noticed/tested by: jilles
Diffstat (limited to 'sysutils/xfce4-cpugraph-plugin')
-rw-r--r--sysutils/xfce4-cpugraph-plugin/Makefile2
-rw-r--r--sysutils/xfce4-cpugraph-plugin/files/patch-panel-plugin__os.c43
2 files changed, 29 insertions, 16 deletions
diff --git a/sysutils/xfce4-cpugraph-plugin/Makefile b/sysutils/xfce4-cpugraph-plugin/Makefile
index a28bbf53fa9d..70a7756df804 100644
--- a/sysutils/xfce4-cpugraph-plugin/Makefile
+++ b/sysutils/xfce4-cpugraph-plugin/Makefile
@@ -7,7 +7,7 @@
PORTNAME= xfce4-cpugraph-plugin
PORTVERSION= 1.0.1
-PORTREVISION= 2
+PORTREVISION= 3
CATEGORIES= sysutils xfce
MASTER_SITES= ${MASTER_SITE_XFCE}
MASTER_SITE_SUBDIR= src/panel-plugins/${PORTNAME}/${PORTVERSION:R}
diff --git a/sysutils/xfce4-cpugraph-plugin/files/patch-panel-plugin__os.c b/sysutils/xfce4-cpugraph-plugin/files/patch-panel-plugin__os.c
index 0faad0cb5765..c8828891563c 100644
--- a/sysutils/xfce4-cpugraph-plugin/files/patch-panel-plugin__os.c
+++ b/sysutils/xfce4-cpugraph-plugin/files/patch-panel-plugin__os.c
@@ -1,6 +1,6 @@
--- panel-plugin/os.c.orig 2010-11-07 13:58:22.000000000 +0100
-+++ panel-plugin/os.c 2011-12-18 13:52:22.000000000 +0100
-@@ -134,28 +134,41 @@
++++ panel-plugin/os.c 2011-12-31 17:30:16.000000000 +0100
+@@ -134,28 +134,54 @@
#elif defined (__FreeBSD__)
guint detect_cpu_number()
{
@@ -18,24 +18,23 @@
{
glong used, total;
- glong cp_time[CPUSTATES];
-+ glong cp_time[CPUSTATES * nb_cpu];
+- gsize len = sizeof( cp_time );
++ glong *cp_time;
+ glong *cp_time1;
- gsize len = sizeof( cp_time );
+ gint i;
++ unsigned int max_cpu;
++ gsize len = sizeof(max_cpu);
- if( sysctlbyname( "kern.cp_time", &cp_time, &len, NULL, 0 ) < 0 )
+ data[0].load = 0;
-+ if( sysctlbyname( "kern.cp_times", &cp_time, &len, NULL, 0 ) < 0 )
++ if (sysctlbyname("kern.smp.maxid", &max_cpu, &len, NULL, 0) < 0)
return FALSE;
-+ for (i = 1; i <= nb_cpu; i++ )
-+ {
-+ cp_time1 = cp_time + CPUSTATES * (i - 1);
-+ used = cp_time1[CP_USER] + cp_time1[CP_NICE] + cp_time1[CP_SYS] + cp_time1[CP_INTR];
-+ total = used + cp_time1[CP_IDLE];
-+ if( (total - data[i].previous_total) != 0 )
-+ data[i].load = (CPU_SCALE * (used - data[i].previous_used))/(total - data[i].previous_total);
-+ else
-+ data[i].load = 0;
++
++ max_cpu++; /* max_cpu is 0-based */
++ if (max_cpu < nb_cpu)
++ return FALSE; /* should not happen */
++ len = sizeof(glong) * max_cpu * CPUSTATES;
++ cp_time = (glong *) g_malloc(len);
- used = cp_time[CP_USER] + cp_time[CP_NICE] + cp_time[CP_SYS] + cp_time[CP_INTR];
- total = used + cp_time[CP_IDLE];
@@ -46,12 +45,26 @@
-
- data[0].previous_used = used;
- data[0].previous_total = total;
--
++ if (sysctlbyname( "kern.cp_times", cp_time, &len, NULL, 0 ) < 0) {
++ g_free(cp_time);
++ return FALSE;
++ }
++ for (i = 1; i <= nb_cpu; i++ )
++ {
++ cp_time1 = &cp_time[CPUSTATES * (i - 1)];
++ used = cp_time1[CP_USER] + cp_time1[CP_NICE] + cp_time1[CP_SYS] + cp_time1[CP_INTR];
++ total = used + cp_time1[CP_IDLE];
++ if( (total - data[i].previous_total) != 0 )
++ data[i].load = (CPU_SCALE * (used - data[i].previous_used))/(total - data[i].previous_total);
++ else
++ data[i].load = 0;
+
+ data[i].previous_used = used;
+ data[i].previous_total = total;
+ data[0].load += data[i].load;
+ }
+ data[0].load /= nb_cpu;
++ g_free(cp_time);
return TRUE;
}