summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f24b091)
raw | patch | inline | side by side (parent: f24b091)
author | Darrell Bishop <darrellb@acm.org> | |
Sat, 5 Nov 2011 08:29:00 +0000 (09:29 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 1 Mar 2012 06:22:34 +0000 (07:22 +0100) |
Fixes GitHub issue #11.
Change-Id: Ifa9db0e020f19da43bbf49bba0626e70c16dc30f
Change-Id: Ifa9db0e020f19da43bbf49bba0626e70c16dc30f
src/processes.c | patch | blob | history |
diff --git a/src/processes.c b/src/processes.c
index d56be25b8245f173e7a2fb47870428480e04e6a7..37e84c5a00d6e63a297413a190b63c1487bc9fbc 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
char *fields[64];
char fields_len;
+ char *bufp, *namep;
int i;
- int name_len;
long long unsigned cpu_user_counter;
long long unsigned cpu_system_counter;
return (-1);
buffer[i] = 0;
+ /* Parse out ps->name while sanitizing any whitespace ( \t\r\n) in
+ the process name before calling strsplit
+ */
+ for (bufp = buffer; *bufp != '\0' && *bufp != '('; bufp++);
+ if (*bufp == '\0' || *(++bufp) == '\0')
+ return (-1);
+ namep = ps->name;
+ while (*bufp != '\0' && *bufp != ')') {
+ *namep++ = *bufp;
+ if (*bufp == ' ' || *bufp == '\t' || *bufp == '\r' || *bufp == '\n')
+ *bufp = '_';
+ bufp++;
+ }
+ *namep = '\0';
+
fields_len = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
if (fields_len < 24)
{
return (-1);
}
- /* copy the name, strip brackets in the process */
- name_len = strlen (fields[1]) - 2;
- if ((fields[1][0] != '(') || (fields[1][name_len + 1] != ')'))
- {
- DEBUG ("No brackets found in process name: `%s'", fields[1]);
- return (-1);
- }
- fields[1] = fields[1] + 1;
- fields[1][name_len] = '\0';
- strncpy (ps->name, fields[1], PROCSTAT_NAME_LEN);
-
-
*state = fields[2][0];
if (*state == 'Z')