From nobody@FreeBSD.org  Tue Feb 26 23:38:43 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B8B7C106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 26 Feb 2008 23:38:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id A2F3313C45E
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 26 Feb 2008 23:38:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m1QNZwVI054661
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 26 Feb 2008 23:35:58 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m1QNZw1Z054660;
	Tue, 26 Feb 2008 23:35:58 GMT
	(envelope-from nobody)
Message-Id: <200802262335.m1QNZw1Z054660@www.freebsd.org>
Date: Tue, 26 Feb 2008 23:35:58 GMT
From: Benjain Close <benjsc@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] systils/wmbluecpu : Fix broken port under 8, take maintainership
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         121133
>Category:       ports
>Synopsis:       [patch] systils/wmbluecpu : Fix broken port under 8, take maintainership
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ehaupt
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 26 23:40:02 UTC 2008
>Closed-Date:    Wed Feb 27 11:13:10 CET 2008
>Last-Modified:  Wed Feb 27 10:20:01 UTC 2008
>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:
Responsible-Changed-From-To: freebsd-bugs->freebsd-ports-bugs 
Responsible-Changed-By: benjsc 
Responsible-Changed-When: Tue Feb 26 23:57:50 UTC 2008 
Responsible-Changed-Why:  
Put in the right category 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121133 
Responsible-Changed-From-To: freebsd-ports-bugs->ehaupt 
Responsible-Changed-By: ehaupt 
Responsible-Changed-When: Wed Feb 27 10:57:14 CET 2008 
Responsible-Changed-Why:  
I will take care of it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121133 
State-Changed-From-To: open->closed 
State-Changed-By: ehaupt 
State-Changed-When: Wed Feb 27 11:13:09 CET 2008 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121133 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/121133: commit references a PR
Date: Wed, 27 Feb 2008 10:13:05 +0000 (UTC)

 ehaupt      2008-02-27 10:12:56 UTC
 
   FreeBSD ports repository
 
   Modified files:
     sysutils/wmbluecpu   Makefile 
     sysutils/wmbluecpu/files cpu_freebsd.c 
   Log:
   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
   
   Revision  Changes    Path
   1.6       +2 -2      ports/sysutils/wmbluecpu/Makefile
   1.3       +20 -16    ports/sysutils/wmbluecpu/files/cpu_freebsd.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
