diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-01-07 12:47:17 +0200 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-01-07 12:47:17 +0200 |
commit | d38d115801c6ef42d2a6d17942db29f6d9c59fe7 (patch) | |
tree | b5a5ac96776a22e7d0aed2c5cc3e8830b1843de1 /src | |
parent | 48a586291d9840b52ac832ab317231c3dd882d9e (diff) |
disable plugins based on their exit code
Diffstat (limited to 'src')
-rwxr-xr-x | src/plugins_d.c | 11 | ||||
-rwxr-xr-x | src/popen.c | 10 | ||||
-rwxr-xr-x | src/popen.h | 2 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/plugins_d.c b/src/plugins_d.c index 6aae68e11c..ef43ab1a04 100755 --- a/src/plugins_d.c +++ b/src/plugins_d.c @@ -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; } diff --git a/src/popen.c b/src/popen.c index 4f721f5eba..882a4cc5a6 100755 --- a/src/popen.c +++ b/src/popen.c @@ -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; } diff --git a/src/popen.h b/src/popen.h index 2f00694263..10680f0c82 100755 --- a/src/popen.h +++ b/src/popen.h @@ -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 */ |