From: Bart De Vos Date: Fri, 30 Aug 2019 07:12:34 +0000 (+0200) Subject: plugin: processes: return error if procs_running can not be retrieved X-Git-Tag: collectd-5.11.0~8^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=565be346ba6e7dfe5f768a200eb4703e16d44689;p=thirdparty%2Fcollectd.git plugin: processes: return error if procs_running can not be retrieved Although returning '1' is probably right, it's up to the application to decide. The data structure for number of running processes is an 'int', so '-1' clearly indicates something's wrong when interpreting the data. Conflicts: src/processes.c --- diff --git a/src/processes.c b/src/processes.c index 2cf88a2fe..d7e3f2190 100644 --- a/src/processes.c +++ b/src/processes.c @@ -1433,6 +1433,8 @@ static int procs_running(void) { char buffer[4096] = {}; char id[] = "procs_running "; /* white space terminated */ char *running; + char *endptr = NULL; + long result = 0L; ssize_t status; @@ -1449,12 +1451,17 @@ static int procs_running(void) { */ running = strstr(buffer, id); if (!running) { - WARNING("procs_running not found, assuming 1"); - return 1; + WARNING("procs_running not found"); + return -1; } running += strlen(id); - return atoi(running); + result = strtol(running, &endptr, 10); + if ( (*running != '\0') && ((*endptr == '\0') || (*endptr == '\n')) ) { + return (int)result; + } + + return -1; } static char *ps_get_cmdline(long pid, char *name, char *buf, size_t buf_len) {