]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
plugin: processes: return error if procs_running can not be retrieved
authorBart De Vos <bart-de-vos@telenet.be>
Fri, 30 Aug 2019 07:12:34 +0000 (09:12 +0200)
committerBart De Vos <bart-de-vos@telenet.be>
Fri, 30 Aug 2019 07:15:43 +0000 (09:15 +0200)
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

src/processes.c

index 2cf88a2fe938cc68a9574d0cdd19bb16f808732d..d7e3f2190b411d0d74db457cf05d3257d38bda04 100644 (file)
@@ -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) {