-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectd-5.0.1-fix-irq-error.diff
60 lines (55 loc) · 1.47 KB
/
collectd-5.0.1-fix-irq-error.diff
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
diff -ur collectd-5.0.1.dist/src/irq.c collectd-5.0.1/src/irq.c
--- collectd-5.0.1.dist/src/irq.c 2011-10-14 22:49:49.000000000 +0200
+++ collectd-5.0.1/src/irq.c 2012-01-19 01:19:01.061471232 +0100
@@ -130,6 +130,8 @@
{
FILE *fh;
char buffer[1024];
+ int cpu_count;
+ char *fields[64];
fh = fopen ("/proc/interrupts", "r");
if (fh == NULL)
@@ -140,20 +142,36 @@
return (-1);
}
+ /* Get CPU count from the first line */
+ if(fgets (buffer, sizeof (buffer), fh) != NULL) {
+ cpu_count = strsplit (buffer, fields, 64);
+ } else {
+ ERROR ("irq plugin: unable to get CPU count from first line of /proc/interrupts");
+ return (-1);
+ }
+
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
char *irq_name;
size_t irq_name_len;
derive_t irq_value;
int i;
-
- char *fields[64];
int fields_num;
+ int irq_values_to_parse;
fields_num = strsplit (buffer, fields, 64);
if (fields_num < 2)
continue;
+ /* Parse this many numeric fields, skip the rest
+ * (+1 because first there is a name of irq in each line) */
+ if (fields_num >= cpu_count+1) {
+ irq_values_to_parse = cpu_count;
+ } else {
+ irq_values_to_parse = fields_num - 1;
+ }
+
+ /* First field is irq name */
irq_name = fields[0];
irq_name_len = strlen (irq_name);
if (irq_name_len < 2)
@@ -168,7 +186,7 @@
irq_name_len--;
irq_value = 0;
- for (i = 1; i < fields_num; i++)
+ for (i = 1; i <= irq_values_to_parse; i++)
{
/* Per-CPU value */
value_t v;