X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fprocesses.c;h=b6c47bfa431e8cd4f0df9c165d4cbb51638bc21f;hb=aef15b632b9f415e5ebfadd4e41fa8a3c19407ee;hp=efc64d0125af349a115bdd3c9b2bbcae7f8f30d4;hpb=810e8f5d687514841ed0ea445764ccc05e8f5299;p=collectd.git diff --git a/src/processes.c b/src/processes.c index efc64d01..b6c47bfa 100644 --- a/src/processes.c +++ b/src/processes.c @@ -128,6 +128,7 @@ # undef SAVE_FOB_64 #endif +# include # include /* #endif KERNEL_SOLARIS */ @@ -538,6 +539,12 @@ static int ps_config (oconfig_item_t *ci) { int i; +#if KERNEL_LINUX + const size_t max_procname_len = 15; +#elif KERNEL_SOLARIS || KERNEL_FREEBSD + const size_t max_procname_len = MAXCOMLEN -1; +#endif + for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; @@ -558,6 +565,15 @@ static int ps_config (oconfig_item_t *ci) c->children_num, c->values[0].value.string); } +#if KERNEL_LINUX || KERNEL_SOLARIS || KERNEL_FREEBSD + if (strlen (c->values[0].value.string) > max_procname_len) { + WARNING ("processes plugin: this platform has a %zu character limit " + "to process names. The `Process \"%s\"' option will " + "not work as expected.", + max_procname_len, c->values[0].value.string); + } +#endif + ps_list_register (c->values[0].value.string, NULL); } else if (strcasecmp (c->key, "ProcessMatch") == 0) @@ -1038,13 +1054,11 @@ static int ps_read_process (long pid, procstat_t *ps, char *state) * strchr(3) and strrchr(3) to avoid pointer arithmetic which would * otherwise be required to determine name_len. */ name_start_pos = 0; - while ((buffer[name_start_pos] != '(') - && (name_start_pos < buffer_len)) + while (name_start_pos < buffer_len && buffer[name_start_pos] != '(') name_start_pos++; name_end_pos = buffer_len; - while ((buffer[name_end_pos] != ')') - && (name_end_pos > 0)) + while (name_end_pos > 0 && buffer[name_end_pos] != ')') name_end_pos--; /* Either '(' or ')' is not found or they are in the wrong order. @@ -1092,7 +1106,7 @@ static int ps_read_process (long pid, procstat_t *ps, char *state) ps->vmem_code = -1; DEBUG("ps_read_process: did not get vmem data for pid %li", pid); } - if (ps->num_lwp <= 0) + if (ps->num_lwp == 0) ps->num_lwp = 1; ps->num_proc = 1; } @@ -1216,7 +1230,7 @@ static char *ps_get_cmdline (long pid, char *name, char *buf, size_t buf_len) buf_ptr += status; len -= status; - if (len <= 0) + if (len == 0) break; }