Date: Tue, 26 Feb 2008 23:35:58 GMT From: Benjain Close <benjsc@FreeBSD.org> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/121133: [patch] systils/wmbluecpu : Fix broken port under 8, take maintainership Message-ID: <200802262335.m1QNZw1Z054660@www.freebsd.org> Resent-Message-ID: <200802262340.m1QNe2at048222@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 121133 >Category: misc >Synopsis: [patch] systils/wmbluecpu : Fix broken port under 8, take maintainership >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Feb 26 23:40:02 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Benjain Close >Release: FreeBSD 8.0-Current >Organization: ClearChain >Environment: FreeBSD wolf.clearchain.com 8.0-CURRENT FreeBSD 8.0-CURRENT #1: Fri Dec 14 14:23:25 CST 2007 root@wolf.clearchain.com:/usr/src-local/sys/amd64/compile/GENERIC amd64 >Description: 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). The attached patch fixes this and *should* be backward compatible under 7 and below (I've no 7 or less boxes to test on). I'm also happy to take maintainership of this port. Please not however, I've only a src commit bit. >How-To-Repeat: Run wmbluecpu on 8.0-Current >Fix: Apply attached patch Patch attached with submission follows: Index: Makefile =================================================================== RCS file: /devel/FreeBSD/ncvs/ports/sysutils/wmbluecpu/Makefile,v retrieving revision 1.5 diff -u -r1.5 Makefile --- Makefile 19 May 2007 20:23:36 -0000 1.5 +++ Makefile 26 Feb 2008 23:32:34 -0000 @@ -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 Index: files/cpu_freebsd.c =================================================================== RCS file: /devel/FreeBSD/ncvs/ports/sysutils/wmbluecpu/files/cpu_freebsd.c,v retrieving revision 1.2 diff -u -r1.2 cpu_freebsd.c --- files/cpu_freebsd.c 10 Apr 2003 09:46:22 -0000 1.2 +++ files/cpu_freebsd.c 26 Feb 2008 23:31:59 -0000 @@ -35,23 +35,17 @@ #include <unistd.h> 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 @@ 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]; >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802262335.m1QNZw1Z054660>