@cryptotaxi247 / netdata-1 / commits / 4a6c04043

works with processes with a space in them

Costa Tsaousis (ktsaou) committed May 8, 2014 at 03:13 UTC 4a6c040437c439c0cd32653c455a592f31219edf
1 file changed +6 -6
apps_plugin.c
+6 -6
@@ -32,7 +32,7 @@ long pid_max = 32768;
32 int debug = 0;
33
34 struct wanted {
35 - char compare[MAX_COMPARE_NAME + 3];
35 + char compare[MAX_COMPARE_NAME + 1];
36 char id[MAX_NAME + 1];
37 char name[MAX_NAME + 1];
38
@@ -79,7 +79,7 @@ struct wanted *get_wanted(const char *id, struct wanted *target)
79
80 strncpy(w->id, id, MAX_NAME);
81 strncpy(w->name, id, MAX_NAME);
82 - snprintf(w->compare, MAX_COMPARE_NAME+1, "(%.*s)", MAX_COMPARE_NAME, id);
82 + strncpy(w->compare, id, MAX_COMPARE_NAME);
83 w->target = target;
84
85 w->next = wanted_root;
@@ -132,7 +132,7 @@ void parse_args(int argc, char **argv)
132 // see: man proc
133 struct pid_stat {
134 int32_t pid;
135 - char comm[MAX_COMPARE_NAME + 3];
135 + char comm[MAX_COMPARE_NAME + 1];
136 char state;
137 int32_t ppid;
138 int32_t pgrp;
@@ -296,7 +296,7 @@ int update_from_proc(void)
296 if(!p) continue;
297
298 int parsed = sscanf(buffer,
299 - "%d %s %c" // pid, comm, state
299 + "%d (%[^)]) %c" // pid, comm, state
300 " %d %d %d %d %d" // ppid, pgrp, session, tty_nr, tpgid
301 " %lu %llu %llu %llu %llu" // flags, minflt, cminflt, majflt, cmajflt
302 " %llu %llu %llu %llu" // utime, stime, cutime, cstime
@@ -329,8 +329,8 @@ int update_from_proc(void)
329 , &p->rt_priority, &p->policy
330 , &p->delayacct_blkio_ticks, &p->guest_time, &p->cguest_time
331 );
332 - strncpy(p->comm, name, MAX_COMPARE_NAME + 2);
333 - p->comm[MAX_COMPARE_NAME + 2] = '\0';
332 + strncpy(p->comm, name, MAX_COMPARE_NAME);
333 + p->comm[MAX_COMPARE_NAME] = '\0';
334
335 if(debug) fprintf(stderr, "VALUES: %s utime=%llu, stime=%llu, cutime=%llu, cstime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->utime, p->stime, p->cutime, p->cstime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
336