]> arthur.barton.de Git - netdata.git/blobdiff - src/plugins_d.c
improvements identified via static code analysis with cppcheck
[netdata.git] / src / plugins_d.c
index 627cc90e5f443543c6f42382d26d7ab3b692db88..4053653233bb0f181e5723075999e1c8227a5b57 100644 (file)
@@ -109,7 +109,7 @@ void *pluginsd_worker_thread(void *arg)
 
     size_t count = 0;
 
-    while(likely(1)) {
+    for(;;) {
         if(unlikely(netdata_exit)) break;
 
         FILE *fp = mypopen(cd->cmd, &cd->pid);
@@ -121,7 +121,6 @@ void *pluginsd_worker_thread(void *arg)
         info("PLUGINSD: '%s' running on pid %d", cd->fullfilename, cd->pid);
 
         RRDSET *st = NULL;
-        char *s;
         uint32_t hash;
 
         while(likely(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL)) {
@@ -132,7 +131,7 @@ void *pluginsd_worker_thread(void *arg)
             // debug(D_PLUGINSD, "PLUGINSD: %s: %s", cd->filename, line);
 
             int w = pluginsd_split_words(line, words, MAX_WORDS);
-            s = words[0];
+            char *s = words[0];
             if(unlikely(!s || !*s || !w)) {
                 // debug(D_PLUGINSD, "PLUGINSD: empty line");
                 continue;
@@ -189,7 +188,7 @@ void *pluginsd_worker_thread(void *arg)
                     unsigned long long microseconds = 0;
                     if(microseconds_txt && *microseconds_txt) microseconds = strtoull(microseconds_txt, NULL, 10);
                     if(microseconds) rrdset_next_usec(st, microseconds);
-                    else rrdset_next_plugins(st);
+                    else rrdset_next(st);
                 }
             }
             else if(likely(hash == END_HASH && !strcmp(s, "END"))) {
@@ -358,7 +357,7 @@ void *pluginsd_worker_thread(void *arg)
                 error("PLUGINSD: %s sleeping for %llu. Will kill with SIGCONT pid %d to wake it up.\n", cd->fullfilename, susec, cd->pid);
                 usleep(susec);
                 killpid(cd->pid, SIGCONT);
-                bcopy(&now, &last, sizeof(struct timeval));
+                memmove(&last, &now, sizeof(struct timeval));
                 break;
             }
 #endif
@@ -380,16 +379,9 @@ void *pluginsd_worker_thread(void *arg)
 
         // get the return code
         int code = mypclose(fp, cd->pid);
-
-        if(netdata_exit) {
-            cd->pid = 0;
-            cd->enabled = 0;
-            cd->obsolete = 1;
-            pthread_exit(NULL);
-            return NULL;
-        }
-
-        if(code != 0) {
+        
+        if(unlikely(netdata_exit)) break;
+        else if(code != 0) {
             // the plugin reports failure
 
             if(likely(!cd->successful_collections)) {
@@ -401,7 +393,7 @@ void *pluginsd_worker_thread(void *arg)
                 // we have collected something
 
                 if(likely(cd->serial_failures <= 10)) {
-                    error("PLUGINSD: '%s' exited with error code %d, but has given useful output in the past (%zu times). Waiting a bit before starting it again.", cd->fullfilename, code, cd->successful_collections);
+                    error("PLUGINSD: '%s' exited with error code %d, but has given useful output in the past (%zu times). %s", cd->fullfilename, code, cd->successful_collections, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is disabled.");
                     sleep((unsigned int) (cd->update_every * 10));
                 }
                 else {
@@ -417,7 +409,7 @@ void *pluginsd_worker_thread(void *arg)
                 // we have collected nothing so far
 
                 if(likely(cd->serial_failures <= 10)) {
-                    error("PLUGINSD: '%s' (pid %d) does not generate useful output but it reports success (exits with 0). Waiting a bit before starting it again.", cd->fullfilename, cd->pid);
+                    error("PLUGINSD: '%s' (pid %d) does not generate useful output but it reports success (exits with 0). %s.", cd->fullfilename, cd->pid, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is disabled.");
                     sleep((unsigned int) (cd->update_every * 10));
                 }
                 else {
@@ -430,10 +422,11 @@ void *pluginsd_worker_thread(void *arg)
         }
         cd->pid = 0;
 
-        if(unlikely(!cd->enabled))
-            break;
+        if(unlikely(!cd->enabled)) break;
     }
 
+    info("PLUGINSD: '%s' thread exiting", cd->fullfilename);
+
     cd->obsolete = 1;
     pthread_exit(NULL);
     return NULL;
@@ -462,7 +455,7 @@ void *pluginsd_main(void *ptr) {
 
     if(scan_frequency < 1) scan_frequency = 1;
 
-    while(likely(1)) {
+    for(;;) {
         if(unlikely(netdata_exit)) break;
 
         dir = opendir(dir_name);
@@ -542,6 +535,8 @@ void *pluginsd_main(void *ptr) {
         sleep((unsigned int) scan_frequency);
     }
 
+    info("PLUGINS.D thread exiting");
+
     pthread_exit(NULL);
     return NULL;
 }