]> arthur.barton.de Git - netdata.git/commitdiff
workaround for self-kill
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Mon, 14 Sep 2015 14:14:36 +0000 (17:14 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Mon, 14 Sep 2015 14:14:36 +0000 (17:14 +0300)
src/main.c
src/plugins_d.c

index 68ac66c1b32bf272d317430559e6c9beea83113b..08c5d61ad541288ad4376bee66c8d768929aa90f 100755 (executable)
@@ -82,9 +82,11 @@ void kill_childs()
        }
 
        if(tc_child_pid) {
-               debug(D_EXIT, "Killing tc-qos-helper procees");
-               kill(tc_child_pid, SIGTERM);
-               waitid(tc_child_pid, 0, &info, WEXITED);
+               if(kill(tc_child_pid, 0) != -1) {
+                       info("Killing tc-qos-helper procees");
+                       kill(tc_child_pid, SIGTERM);
+                       waitid(tc_child_pid, 0, &info, WEXITED);
+               }
        }
        tc_child_pid = 0;
 
@@ -95,9 +97,11 @@ void kill_childs()
                pthread_join(cd->thread, NULL);
 
                if(cd->pid && !cd->obsolete) {
-                       debug(D_EXIT, "killing %s plugin process", cd->id);
-                       kill(cd->pid, SIGTERM);
-                       waitid(cd->pid, 0, &info, WEXITED);
+                       if(kill(cd->pid, 0) != -1) {
+                               debug(D_EXIT, "killing %s plugin process", cd->id);
+                               kill(cd->pid, SIGTERM);
+                               waitid(cd->pid, 0, &info, WEXITED);
+                       }
                }
        }
 
index 1bc567752b488cc765206bc95429bd4ea36a846f..2fe5c56baf6bed014f96e0d2a8048f5a866ad9b1 100755 (executable)
@@ -152,7 +152,8 @@ void *pluginsd_worker_thread(void *arg)
                                if(!dimension || !*dimension) {
                                        error("PLUGINSD: '%s' is requesting a SET on chart '%s', like this: 'SET %s = %s'. Disabling it.", cd->fullfilename, st->id, dimension?dimension:"<nothing>", value?value:"<nothing>");
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
@@ -161,7 +162,8 @@ void *pluginsd_worker_thread(void *arg)
                                if(!st) {
                                        error("PLUGINSD: '%s' is requesting a SET on dimension %s with value %s, without a BEGIN. Disabling it.", cd->fullfilename, dimension, value);
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
@@ -177,7 +179,8 @@ void *pluginsd_worker_thread(void *arg)
                                if(!id) {
                                        error("PLUGINSD: '%s' is requesting a BEGIN without a chart id. Disabling it.", cd->fullfilename);
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
@@ -185,7 +188,8 @@ void *pluginsd_worker_thread(void *arg)
                                if(!st) {
                                        error("PLUGINSD: '%s' is requesting a BEGIN on chart '%s', which does not exist. Disabling it.", cd->fullfilename, id);
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
@@ -200,7 +204,8 @@ void *pluginsd_worker_thread(void *arg)
                                if(!st) {
                                        error("PLUGINSD: '%s' is requesting an END, without a BEGIN. Disabling it.", cd->fullfilename);
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
@@ -234,7 +239,8 @@ void *pluginsd_worker_thread(void *arg)
                                if(!type || !*type || !id || !*id) {
                                        error("PLUGINSD: '%s' is requesting a CHART, without a type.id. Disabling it.", cd->fullfilename);
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
@@ -282,14 +288,16 @@ void *pluginsd_worker_thread(void *arg)
                                if(!id || !*id) {
                                        error("PLUGINSD: '%s' is requesting a DIMENSION, without an id. Disabling it.", cd->fullfilename);
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
                                if(!st) {
                                        error("PLUGINSD: '%s' is requesting a DIMENSION, without a CHART. Disabling it.", cd->fullfilename);
                                        cd->enabled = 0;
-                                       kill(cd->pid, SIGTERM);
+                                       // test: killing an exited child kills us - lets check it exists before killing it
+                                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                        break;
                                }
 
@@ -323,7 +331,8 @@ void *pluginsd_worker_thread(void *arg)
                        else if(hash == DISABLE_HASH && !strcmp(s, "DISABLE")) {
                                error("PLUGINSD: '%s' called DISABLE. Disabling it.", cd->fullfilename);
                                cd->enabled = 0;
-                               kill(cd->pid, SIGTERM);
+                               // test: killing an exited child kills us - lets check it exists before killing it
+                               if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                break;
                        }
 #ifdef DETACH_PLUGINS_FROM_NETDATA
@@ -352,7 +361,8 @@ 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);
-                               kill(cd->pid, SIGCONT);
+                               // test: killing an exited child kills us - lets check it exists before killing it
+                               if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGCONT);
                                bcopy(&now, &last, sizeof(struct timeval));
                                break;
                        }
@@ -360,7 +370,8 @@ void *pluginsd_worker_thread(void *arg)
                        else {
                                error("PLUGINSD: '%s' is sending command '%s' which is not known by netdata. Disabling it.", cd->fullfilename, s);
                                cd->enabled = 0;
-                               kill(cd->pid, SIGTERM);
+                               // test: killing an exited child kills us - lets check it exists before killing it
+                               if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                                break;
                        }
                }
@@ -372,7 +383,8 @@ void *pluginsd_worker_thread(void *arg)
                if(!count && cd->enabled) {
                        error("PLUGINSD: '%s' does not generate usefull output. Disabling it.", cd->fullfilename);
                        cd->enabled = 0;
-                       kill(cd->pid, SIGTERM);
+                       // test: killing an exited child kills us - lets check it exists before killing it
+                       if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
                }
 
                if(cd->enabled) sleep(cd->update_every);