summaryrefslogtreecommitdiff
path: root/net-mgmt/net-snmp/files/patch-kthreads
blob: 30971a1d13f2ea0086c1ce5ae2f536fe407d725d (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
diff --git a/agent/mibgroup/host/data_access/swrun.c b/agent/mibgroup/host/data_access/swrun.c
index d18ea5f..60ad5b4 100644
--- agent/mibgroup/host/data_access/swrun.c
+++ agent/mibgroup/host/data_access/swrun.c
@@ -75,10 +75,27 @@ shutdown_swrun(void)
 }
 
 int
-swrun_count_processes( void )
+swrun_count_processes(int include_kthreads)
 {
+    netsnmp_swrun_entry *entry;
+    netsnmp_iterator  *it;
+    int i = 0;
+
     netsnmp_cache_check_and_reload(swrun_cache);
-    return ( swrun_container ? CONTAINER_SIZE(swrun_container) : 0 );
+    if ( !swrun_container )
+        return 0;    /* or -1 */
+
+    if (include_kthreads)
+	return ( swrun_container ? CONTAINER_SIZE(swrun_container) : 0 );
+
+    it = CONTAINER_ITERATOR( swrun_container );
+    while ((entry = (netsnmp_swrun_entry*)ITERATOR_NEXT( it )) != NULL) {
+        if (4 == entry->hrSWRunType)
+            i++;
+    }
+    ITERATOR_RELEASE( it );
+
+    return i;
 }
 
 #ifndef NETSNMP_FEATURE_REMOVE_SWRUN_MAX_PROCESSES
diff --git a/agent/mibgroup/host/hr_system.c b/agent/mibgroup/host/hr_system.c
index d99cc7d..e853779 100644
--- agent/mibgroup/host/hr_system.c
+++ agent/mibgroup/host/hr_system.c
@@ -24,6 +24,7 @@
 
 #include <net-snmp/net-snmp-includes.h>
 #include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/data_access/swrun.h>
 
 #include "host.h"
 #include "host_res.h"
@@ -114,7 +115,14 @@ static long     get_max_solaris_processes(void);
 static int      get_load_dev(void);
 static int      count_users(void);
 extern int      count_processes(void);
-extern int      swrun_count_processes(void);
+#if USING_HOST_DATA_ACCESS_SWRUN_MODULE
+static int      count_kthreads = 0;
+
+static void parse_count_kthreads(const char *token, const char *line)
+{
+    count_kthreads = atoi(line);
+}
+#endif
 
         /*********************
 	 *
@@ -194,6 +202,11 @@ init_hr_system(void)
 #ifdef NPROC_SYMBOL
     auto_nlist(NPROC_SYMBOL, 0, 0);
 #endif
+#if USING_HOST_DATA_ACCESS_SWRUN_MODULE
+    snmpd_register_const_config_handler("count_kthreads",
+                                        parse_count_kthreads, NULL,
+					"0|1    0 to exclude kernel threads from hrSystemProcesses.0");
+#endif
 
     REGISTER_MIB("host/hr_system", hrsystem_variables, variable2,
                  hrsystem_variables_oid);
@@ -317,7 +330,7 @@ var_hrsys(struct variable * vp,
         return (u_char *) & long_return;
     case HRSYS_PROCS:
 #if USING_HOST_DATA_ACCESS_SWRUN_MODULE
-        long_return = swrun_count_processes();
+        long_return = swrun_count_processes(count_kthreads);
 #elif USING_HOST_HR_SWRUN_MODULE
         long_return = count_processes();
 #else
diff --git a/include/net-snmp/data_access/swrun.h b/include/net-snmp/data_access/swrun.h
index 3e15c41..4f768ac 100644
--- include/net-snmp/data_access/swrun.h
+++ include/net-snmp/data_access/swrun.h
@@ -85,7 +85,7 @@ extern "C" {
 
     void netsnmp_swrun_entry_free(netsnmp_swrun_entry *entry);
 
-    int  swrun_count_processes( void );
+    int  swrun_count_processes( int include_kthreads );
     int  swrun_max_processes(   void );
     int  swrun_count_processes_by_name( char *name );