From 35f2cdab6f2741c5f5f29c912f5fd2f86b99014a Mon Sep 17 00:00:00 2001 From: Emanuel Haupt Date: Wed, 27 Feb 2008 10:12:56 +0000 Subject: sysutils/wmbluecpu builds under 8.0-CURRENT but exits as soon as run. It fails due to a legacy kvm call being changed. (8.0 uses a sysctl, before used a kvm call). This patch fixes that problem. Pass maintainership to submitter. PR: 121133 Submitted by: benjsc --- sysutils/wmbluecpu/Makefile | 4 ++-- sysutils/wmbluecpu/files/cpu_freebsd.c | 36 +++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'sysutils/wmbluecpu') diff --git a/sysutils/wmbluecpu/Makefile b/sysutils/wmbluecpu/Makefile index 46a1ac3463b9..386634bdb03d 100644 --- a/sysutils/wmbluecpu/Makefile +++ b/sysutils/wmbluecpu/Makefile @@ -7,12 +7,12 @@ PORTNAME= wmbluecpu PORTVERSION= 0.4 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= sysutils windowmaker MASTER_SITES= ${MASTER_SITE_SUNSITE} MASTER_SITE_SUBDIR= X11/xutils -MAINTAINER= ports@FreeBSD.org +MAINTAINER= benjsc@FreeBSD.org COMMENT= A CPU monitoring dockapp USE_BZIP2= yes diff --git a/sysutils/wmbluecpu/files/cpu_freebsd.c b/sysutils/wmbluecpu/files/cpu_freebsd.c index 36440aea422a..62fb2a8fc7b7 100644 --- a/sysutils/wmbluecpu/files/cpu_freebsd.c +++ b/sysutils/wmbluecpu/files/cpu_freebsd.c @@ -35,23 +35,17 @@ #include static kvm_t *kd; -static struct nlist nlst[] = { {"_cp_time"}, {0} }; +static int cp_time_mib[2]; +static struct nlist nlst[] = { + {"_cp_time"}, {0}}; void cpu_init(void) { - if (!(kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open"))) - { - perror("kvm_open"); - exit(1); - } - - kvm_nlist(kd, nlst); - - if (!nlst[0].n_type) - { - perror("kvm_nlist"); - exit(1); + size_t len = 2; + sysctlnametomib("kern.cp_time", cp_time_mib, &len); + if((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) != NULL ){ + kvm_nlist(kd, nlst); } seteuid(getuid()); @@ -73,13 +67,23 @@ int history[17]; void cpu_getusage() { long cpu, nice, system, idle, used, total; - long cpu_time[CPUSTATES]; + long cpu_time[CPUSTATES], cpu_time_len=sizeof(cpu_time); + int error; - if (kvm_read(kd, nlst[0].n_value, &cpu_time, sizeof(cpu_time)) + if( cp_time_mib[0] != 0 ){ + error = sysctl(cp_time_mib, 2, cpu_time, &cpu_time_len, NULL, 0 ); + if ( error ){ + perror("sysctl, cpu_time_mib"); + exit(1); + } + } + else { + if (kvm_read(kd, nlst[0].n_value, &cpu_time, sizeof(cpu_time)) != sizeof(cpu_time)) - { + { perror("kvm_read"); exit(1); + } } cpu = cpu_time[CP_USER]; -- cgit v1.2.3