On Thu, Mar 27, 2003 at 01:31:36AM -0500, Lester Vecsey ([EMAIL PROTECTED]) 
wrote:
> I compiled gmond on FreeBSD 4.4-RELEASE and I'm running it with a non-root
> account.. /dev/mem on the machine isn't accessible from this account, and so
> theres a segfault on kvm_open when I run gmond. For now I just cleaned out
> the swap function that calls kvm_open in gmond, there were a couple of them.
> I tried './configure --without-kvm' but it didn't seem to leave the config.h
> set properly, which has a HAVE_LIBKVM define.. additionally the gmond
> sources don't use that define around the functions that I had to strip out.
> 
> I don't have a patch for this but I thought I'd submit this info and see if
> others on FreeBSD have encountered something similar.

 Ugh, perhaps I should check the return value of kvm_open so 
 kvm_getswapinfo doesn't try to read a NULL descriptor. Attached is a 
 patch, can you see if it fixes your problem? (It should apply to any
 version, it's only to freebsd.c)



-- 
 Preston Smith                                <[EMAIL PROTECTED]>
 UNIX Analyst                  Purdue University Physics Computer Network
 GPG Fingerprint:      6D27 5DAA F58D C42B 7A6B  8F48 04E4 2465 F353 03F6
Index: gmond/machines/freebsd.c
===================================================================
RCS file: /cvsroot/ganglia/monitor-core/gmond/machines/freebsd.c,v
retrieving revision 1.2
diff -u -r1.2 freebsd.c
--- gmond/machines/freebsd.c    15 Aug 2002 17:17:25 -0000      1.2
+++ gmond/machines/freebsd.c    27 Mar 2003 15:39:12 -0000
@@ -87,14 +87,18 @@
    int totswap, n;
 
    kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open"); 
-   n = kvm_getswapinfo(kd, swap, 1, 0);
-   if (n < 0 || swap[0].ksw_total == 0) { 
-       val.uint32 = 0;
+   if(kd != NULL) {
+    n = kvm_getswapinfo(kd, swap, 1, 0);
+    if (n < 0 || swap[0].ksw_total == 0) { 
+        val.uint32 = 0;
+    }
+    totswap = swap[0].ksw_total;
+    totswap *= getpagesize() / 1024;
+    val.uint32 = totswap;
+    kvm_close(kd);
+   } else { 
+    val.uint32 = 0; 
    }
-   totswap = swap[0].ksw_total;
-   totswap *= getpagesize() / 1024;
-   val.uint32 = totswap;
-   kvm_close(kd);
 
    return val;
 }
@@ -388,13 +392,17 @@
    int totswap, usedswap, freeswap, n;
 
    kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
-   n = kvm_getswapinfo(kd, swap, 1, 0);
-   if (n < 0 || swap[0].ksw_total == 0) {
-       val.uint32 = 0;
+   if(kd != NULL) { 
+    n = kvm_getswapinfo(kd, swap, 1, 0);
+    if (n < 0 || swap[0].ksw_total == 0) {
+        val.uint32 = 0;
+    }
+    totswap = swap[0].ksw_total;
+    usedswap = swap[0].ksw_used;
+    kvm_close(kd);
+   } else {
+    totswap = usedswap = 0;
    }
-   totswap = swap[0].ksw_total;
-   usedswap = swap[0].ksw_used;
-   kvm_close(kd);
 
    freeswap = totswap-usedswap;
    freeswap *= getpagesize() / 1024;

Reply via email to