summaryrefslogtreecommitdiff
path: root/net/net-snmp/patches/patch-ah
blob: ab80b70dfc08325648330b4b59fb88998b7f2cb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
$NetBSD: patch-ah,v 1.5 2010/05/11 04:39:54 adam Exp $

--- agent/mibgroup/hardware/memory/memory_netbsd.c.orig	2006-03-06 16:23:52.000000000 +0000
+++ agent/mibgroup/hardware/memory/memory_netbsd.c	2010-04-21 21:58:02.000000000 +0000
@@ -4,6 +4,7 @@
 #include <net-snmp/agent/hardware/memory.h>
 
 #include <unistd.h>
+#include <errno.h>
 #include <sys/sysctl.h>
 #include <sys/swap.h>
 
@@ -30,7 +31,7 @@
     long           pagesize;
 
     struct uvmexp  uvmexp;
-    int            uvmexp_size  = sizeof(uvmexp);
+    size_t         uvmexp_size  = sizeof(uvmexp);
     int            uvmexp_mib[] = { CTL_VM, VM_UVMEXP };
 
     struct vmtotal total;
@@ -40,16 +41,33 @@
     long            phys_mem;
     long            user_mem;
     size_t          mem_size  = sizeof(phys_mem);
+#if defined(__x86_64__)
+    int             phys_mem_mib[] = { CTL_HW, HW_PHYSMEM64 };
+    int             user_mem_mib[] = { CTL_HW, HW_USERMEM64 };
+#else
     int             phys_mem_mib[] = { CTL_HW, HW_PHYSMEM };
     int             user_mem_mib[] = { CTL_HW, HW_USERMEM };
+#endif
 
     /*
      * Retrieve the memory information from the underlying O/S...
      */
-    sysctl(uvmexp_mib,   2, &uvmexp,   &uvmexp_size,   NULL, 0);
-    sysctl(total_mib,    2, &total,    &total_size,    NULL, 0);
-    sysctl(phys_mem_mib, 2, &phys_mem, &mem_size,      NULL, 0);
-    sysctl(user_mem_mib, 2, &user_mem, &mem_size,      NULL, 0);
+    if (sysctl(uvmexp_mib,   2, &uvmexp,   &uvmexp_size,   NULL, 0) == -1) {
+        snmp_log(LOG_ERR, "sysctl VM_UVMEXP failed (errno %d)\n", errno);
+	return -1;
+    }
+    if (sysctl(total_mib,    2, &total,    &total_size,    NULL, 0) == -1) {
+        snmp_log(LOG_ERR, "sysctl VM_METER failed (errno %d)\n", errno);
+	return -1;
+    }
+    if (sysctl(phys_mem_mib, 2, &phys_mem, &mem_size,      NULL, 0) == -1) {
+        snmp_log(LOG_ERR, "sysctl HW_PHYSMEM failed (errno %d)\n", errno);
+	return -1;
+    }
+    if (sysctl(user_mem_mib, 2, &user_mem, &mem_size,      NULL, 0) == -1) {
+        snmp_log(LOG_ERR, "sysctl HW_USERMEM failed (errno %d)\n", errno);
+	return -1;
+    }
     pagesize = uvmexp.pagesize;
 
     /*