]> arthur.barton.de Git - netdata.git/commitdiff
disable plugins based on their exit code
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 7 Jan 2016 10:47:17 +0000 (12:47 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 7 Jan 2016 10:47:17 +0000 (12:47 +0200)
src/plugins_d.c
src/popen.c
src/popen.h

index 6aae68e11c39fc3f76ba56b64427c489d2540f6e..ef43ab1a04ab48e6cc1c47ea8dff8e91cb2cedff 100755 (executable)
@@ -385,10 +385,16 @@ void *pluginsd_worker_thread(void *arg)
                info("PLUGINSD: '%s' on pid %d stopped.", cd->fullfilename, cd->pid);
 
                // fgets() failed or loop broke
-               mypclose(fp, cd->pid);
-               cd->pid = 0;
+               int code = mypclose(fp, cd->pid);
+               if(code == 1 || code == 127) {
+                       // 1 = DISABLE
+                       // 127 = cannot even run it
+                       error("PLUGINSD: '%s' (pid %d) exited with code %d. Disabling it.", cd->fullfilename, cd->pid, code);
+                       cd->enabled = 0;
+               }
 
                if(netdata_exit) {
+                       cd->pid = 0;
                        cd->enabled = 0;
                        cd->obsolete = 1;
                        return NULL;
@@ -399,6 +405,7 @@ void *pluginsd_worker_thread(void *arg)
                        sleep((unsigned int) (cd->update_every * 10));
                }
 
+               cd->pid = 0;
                if(likely(cd->enabled)) sleep((unsigned int) cd->update_every);
                else break;
        }
index 4f721f5ebab59117460530dfbe971ab75ce808c1..882a4cc5a6ba88537327cd4f53d8b0413d71ca43 100755 (executable)
@@ -121,7 +121,7 @@ FILE *mypopen(const char *command, pid_t *pidptr)
        exit(1);
 }
 
-void mypclose(FILE *fp, pid_t pid) {
+int mypclose(FILE *fp, pid_t pid) {
        debug(D_EXIT, "Request to mypclose() on pid %d", pid);
 
        /*mypopen_del(fp);*/
@@ -132,32 +132,40 @@ void mypclose(FILE *fp, pid_t pid) {
                switch(info.si_code) {
                        case CLD_EXITED:
                                error("pid %d exited with code %d.", info.si_pid, info.si_status);
+                               return(info.si_status);
                                break;
 
                        case CLD_KILLED:
                                error("pid %d killed by signal %d.", info.si_pid, info.si_status);
+                               return(-1);
                                break;
 
                        case CLD_DUMPED:
                                error("pid %d core dumped by signal %d.", info.si_pid, info.si_status);
+                               return(-2);
                                break;
 
                        case CLD_STOPPED:
                                error("pid %d stopped by signal %d.", info.si_pid, info.si_status);
+                               return(0);
                                break;
 
                        case CLD_TRAPPED:
                                error("pid %d trapped by signal %d.", info.si_pid, info.si_status);
+                               return(-4);
                                break;
 
                        case CLD_CONTINUED:
                                error("pid %d continued by signal %d.", info.si_pid, info.si_status);
+                               return(0);
                                break;
 
                        default:
                                error("pid %d gave us a SIGCHLD with code %d and status %d.", info.si_pid, info.si_code, info.si_status);
+                               return(-5);
                                break;
                }
        }
        else error("Cannot waitid() for pid %d", pid);
+       return 0;
 }
index 2f0069426395776931fd776eb5a6becf3f611aff..10680f0c8295903104a195f9576e8b9ba5958e9b 100755 (executable)
@@ -9,6 +9,6 @@
 #define PIPE_WRITE 1
 
 extern FILE *mypopen(const char *command, pid_t *pidptr);
-extern void mypclose(FILE *fp, pid_t pid);
+extern int mypclose(FILE *fp, pid_t pid);
 
 #endif /* NETDATA_POPEN_H */