Subject: pkg/14438: patches for ucd-snmp-4.1.2 to support NetBSD memory and vmstat
To: None <gnats-bugs@gnats.netbsd.org>
From: None <srp@tworoads.net>
List: netbsd-bugs
Date: 11/02/2001 11:53:38
>Number:         14438
>Category:       pkg
>Synopsis:       patches for ucd-snmp-4.1.2 to support NetBSD memory and vmstat
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 02 11:54:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Scott Presnell
>Release:        NetBSD 1.5.2
>Organization:
Self
>Environment:
System: NetBSD srp1 1.5.2 NetBSD 1.5.2 (YUKON) #16: Tue Oct 16 12:23:33 PDT 2001 root@srp4:/usr/src/sys/arch/i386/compile/YUKON i386


>Description:

The vmstat and memory components of agent/mibgroup/ucd-snmp
are not compiled in by default.  The patch to the pkg Makefile
(setting the target to netbsd1) fixes that.

Once compiled, certain errors in vmstat_netbsd1.c become apparent.
The patch to vmstat_netbsd1.c  corrects that.

>How-To-Repeat:

	Install or compile the pkg version of ucd-snmp-4.1.2.
	fire up /usr/pkg/sbin/snmpd
	snmpwalk -m ALL localhost public .1.3.6.1.4.1.2021
	Observe missing memory and systemStats sections

>Fix:

--- Makefile.orig	Fri Nov  2 11:42:14 2001
+++ Makefile	Fri Nov  2 10:44:52 2001
@@ -23,6 +23,7 @@
 USE_SSL=	yes
 
 GNU_CONFIGURE=	yes
+CONFIGURE_ARGS+=--build=i386--netbsd1 --target=i386--netbsd1
 CONFIGURE_ARGS+=--with-defaults --with-libwrap --with-logfile="/var/log/snmpd"
 CONFIGURE_ARGS+=--with-mib-modules="smux host"
 # NOTE: if you do not allow dummy values some tools such as
--- ucd-snmp-4.1.2/agent/mibgroup/ucd-snmp/vmstat_netbsd1.c	Thu Mar 16 08:28:32 2000
+++ work/ucd-snmp-4.1.2/agent/mibgroup/ucd-snmp/vmstat_netbsd1.c	Fri Nov  2 11:38:43 2001
@@ -18,6 +18,7 @@
 #include <sys/ioctl.h>
 #include <sys/sysctl.h>
 #include <sys/vmmeter.h>
+#include <sys/sched.h>
 
 #include <vm/vm_param.h>
 #include <uvm/uvm_extern.h>
@@ -108,11 +109,13 @@
     static time_t time_old;
     static time_t time_diff;
 
-    static long cpu_old[CPUSTATES];
-    static long cpu_new[CPUSTATES];
-    static long cpu_diff[CPUSTATES];
-    static long cpu_total;
-    long cpu_sum;
+    static u_int64_t cpu_old[CPUSTATES];
+    static u_int64_t cpu_new[CPUSTATES];
+    static u_int64_t cpu_diff[CPUSTATES];
+    static u_int64_t cpu_total;
+    int cpu_mib[] = { CTL_KERN, KERN_CP_TIME};
+    int cpu_size = sizeof(cpu_new);
+    u_int64_t cpu_sum;
     double cpu_prc;
 
     static struct uvmexp mem_old, mem_new;
@@ -133,9 +136,18 @@
 	time_diff = time_new - time_old;
 	time_old = time_new;
 
-	/* CPU usage */
-	auto_nlist(CPTIME_SYMBOL, (char *)cpu_new, sizeof (cpu_new));
-	
+
+	/*
+	 * XXX Need to locate the `correct' CPU when looking for this
+	 * XXX in crash dumps.  Just don't report it for now, in that
+	 * XXX case.
+	 */
+	memset(cpu_new, 0, cpu_size);
+	if (sysctl(cpu_mib, 2, cpu_new, &cpu_size, NULL, 0) < 0) {
+	    memset(cpu_new, 0, sizeof(cpu_new));
+	    
+	}	
+
 	cpu_total = 0;
 	
 	for (loop = 0; loop < CPUSTATES; loop++)

>Release-Note:
>Audit-Trail:
>Unformatted: