-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectd-4.10.1-all-irq-patch.diff
178 lines (159 loc) · 4.82 KB
/
collectd-4.10.1-all-irq-patch.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
diff -ur collectd-4.10.1.orig/src/irq.c collectd-4.10.1.new/src/irq.c
--- collectd-4.10.1.orig/src/irq.c 2010-07-09 12:01:59.000000000 +0200
+++ collectd-4.10.1.new/src/irq.c 2010-08-19 23:48:10.000000000 +0200
@@ -41,8 +41,8 @@
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-static unsigned int *irq_list;
-static unsigned int irq_list_num;
+char **irq_list;
+static unsigned int irq_list_num = 0;
/*
* irq_list_action:
@@ -55,32 +55,59 @@
{
if (strcasecmp (key, "Irq") == 0)
{
- unsigned int *temp;
- unsigned int irq;
- char *endptr;
+ char tmp_value[30];
+ char *token;
+ char *new_value;
+ char **temp;
- temp = (unsigned int *) realloc (irq_list, (irq_list_num + 1) * sizeof (unsigned int *));
- if (temp == NULL)
+ /* Check if multiple IRQs have been specified on the same config line */
+ if ((strchr(value, ' ') != NULL) || (strchr(value, ',') != NULL))
{
- fprintf (stderr, "irq plugin: Cannot allocate more memory.\n");
- ERROR ("irq plugin: Cannot allocate more memory.");
+ fprintf (stderr, "irq plugin: Please specify one "
+ "irq at a time: `%s'\n", value);
+ ERROR ( "irq plugin: Please specify one "
+ "irq at a time: `%s'", value);
+ return (-1);
+ }
+
+ /* Unquoted number gets received as x.000000 */
+ strcpy(tmp_value, value);
+ if (strchr(tmp_value, '.') != NULL) {
+ token = strtok(tmp_value, ".");
+ strcpy(tmp_value, token);
+ }
+
+ if (strlen(tmp_value) > 3)
+ {
+ fprintf (stderr, "irq plugin: Max length of irq "
+ "name is three characters: `%s'\n", tmp_value);
+ ERROR ( "irq plugin: Max length of irq "
+ "name is three characters: `%s'", tmp_value);
return (1);
}
- irq_list = temp;
- /* Clear errno, because we need it to see if an error occured. */
- errno = 0;
+ /* Allocate additional memory for value */
+ new_value = malloc(strlen(tmp_value) + 1);
+ if (new_value == NULL)
+ {
+ fprintf (stderr, "irq plugin: Cannot allocate more memory.\n");
+ ERROR ( "irq plugin: Cannot allocate more memory.");
+ return (1);
+ }
+ strcpy(new_value, tmp_value);
- irq = strtol(value, &endptr, 10);
- if ((endptr == value) || (errno != 0))
+ /* Allocate additional memory for pointer in array */
+ temp = (char **) realloc (irq_list, (irq_list_num+1) * sizeof(char *));
+ if (temp == NULL)
{
- fprintf (stderr, "irq plugin: Irq value is not a "
- "number: `%s'\n", value);
- ERROR ("irq plugin: Irq value is not a "
- "number: `%s'", value);
+ fprintf (stderr, "irq plugin: Cannot allocate more memory.\n");
+ ERROR ( "irq plugin: Cannot allocate more memory.");
return (1);
}
- irq_list[irq_list_num] = irq;
+ irq_list = temp;
+ irq_list[irq_list_num] = new_value;
+
+ /* Bump index */
irq_list_num++;
}
else if (strcasecmp (key, "IgnoreSelected") == 0)
@@ -102,7 +129,7 @@
* both, `submit' and `write' to give client and server the ability to
* ignore certain stuff..
*/
-static int check_ignore_irq (const unsigned int irq)
+static int check_ignore_irq (const char *irq)
{
int i;
@@ -110,19 +137,21 @@
return (0);
for (i = 0; (unsigned int)i < irq_list_num; i++)
- if (irq == irq_list[i])
+ if (strcmp(irq, irq_list[i]) == 0)
return (irq_list_action);
return (1 - irq_list_action);
}
-static void irq_submit (unsigned int irq, counter_t value)
+
+
+static void irq_submit (const char *irq_name, counter_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
int status;
- if (check_ignore_irq (irq))
+ if (check_ignore_irq (irq_name))
return;
values[0].counter = value;
@@ -134,13 +163,15 @@
sstrncpy (vl.type, "irq", sizeof (vl.type));
status = ssnprintf (vl.type_instance, sizeof (vl.type_instance),
- "%u", irq);
+ "%s", irq_name);
if ((status < 1) || ((unsigned int)status >= sizeof (vl.type_instance)))
return;
plugin_dispatch_values (&vl);
} /* void irq_submit */
+
+
static int irq_read (void)
{
#undef BUFSIZE
@@ -148,7 +179,7 @@
FILE *fh;
char buffer[BUFSIZE];
- unsigned int irq;
+ char *irq_name;
unsigned long long irq_value;
unsigned long long value;
char *endptr;
@@ -170,12 +201,13 @@
if (fields_num < 2)
continue;
- errno = 0; /* To distinguish success/failure after call */
- irq = strtol (fields[0], &endptr, 10);
-
- if ((endptr == fields[0]) || (errno != 0) || (*endptr != ':'))
+ /* Check if irq name contains colon, it is header otherwise */
+ if (strchr(fields[0], ':') == NULL)
continue;
+ errno = 0; /* To distinguish success/failure after call */
+ irq_name = strtok(fields[0], ":");
+
irq_value = 0;
for (i = 1; i < fields_num; i++)
{
@@ -189,7 +221,7 @@
} /* for (i) */
/* Force 32bit wrap-around */
- irq_submit (irq, irq_value % 4294967296ULL);
+ irq_submit (irq_name, irq_value % 4294967296ULL);
}
fclose (fh);