@cryptotaxi247 / netdata-1 / commits / f0c40b331

more exit cleanup actions

Costa Tsaousis (ktsaou) committed Jan 14, 2017 at 13:53 UTC f0c40b331aa4c3c65650cb164c5fb26dbbbc971f
6 files changed +22 -23
src/main.c
+3 -2
@@ -178,12 +178,13 @@ void kill_childs()
178
179 struct plugind *cd;
180 for(cd = pluginsd_root ; cd ; cd = cd->next) {
181 - if(!cd->obsolete) {
182 - if(cd->thread) {
181 + if(cd->enabled && !cd->obsolete) {
182 + if(cd->thread != (pthread_t)NULL) {
183 info("Stopping %s plugin thread", cd->id);
184 pthread_cancel(cd->thread);
185 // they are detached
186 // pthread_join(cd->thread, NULL);
187 + cd->thread = (pthread_t)NULL;
188 }
189
190 if(cd->pid) {
src/plugin_tc.c
+3 -3
@@ -747,7 +747,7 @@ static inline void tc_split_words(char *str, char **words, int max_words) {
747 while(i < max_words) words[i++] = NULL;
748 }
749
750 -pid_t tc_child_pid = 0;
750 +volatile pid_t tc_child_pid = 0;
751 void *tc_main(void *ptr) {
752 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
753
@@ -793,7 +793,7 @@ void *tc_main(void *ptr) {
793 snprintfz(buffer, TC_LINE_MAX, "exec %s %d", tc_script, rrd_update_every);
794 debug(D_TC_LOOP, "executing '%s'", buffer);
795
796 - fp = mypopen(buffer, &tc_child_pid);
796 + fp = mypopen(buffer, (pid_t *)&tc_child_pid);
797 if(unlikely(!fp)) {
798 error("TC: Cannot popen(\"%s\", \"r\").", buffer);
799 goto cleanup;
@@ -986,7 +986,7 @@ void *tc_main(void *ptr) {
986 }
987
988 // fgets() failed or loop broke
989 - int code = mypclose(fp, tc_child_pid);
989 + int code = mypclose(fp, (pid_t)tc_child_pid);
990 tc_child_pid = 0;
991
992 if(unlikely(device)) {
src/plugin_tc.h
+1 -1
@@ -1,7 +1,7 @@
1 #ifndef NETDATA_PLUGIN_TC_H
2 #define NETDATA_PLUGIN_TC_H 1
3
4 -extern pid_t tc_child_pid;
4 +extern volatile pid_t tc_child_pid;
5 extern void *tc_main(void *ptr);
6
7 #endif /* NETDATA_PLUGIN_TC_H */
src/plugins_d.c
+14 -15
@@ -87,6 +87,8 @@ static int pluginsd_split_words(char *str, char **words, int max_words) {
87 void *pluginsd_worker_thread(void *arg)
88 {
89 struct plugind *cd = (struct plugind *)arg;
90 + cd->obsolete = 0;
91 +
92 char line[PLUGINSD_LINE_MAX + 1];
93
94 #ifdef DETACH_PLUGINS_FROM_NETDATA
@@ -428,7 +430,7 @@ void *pluginsd_worker_thread(void *arg)
430 info("PLUGINSD: '%s' thread exiting", cd->fullfilename);
431
432 cd->obsolete = 1;
431 - cd->thread = 0;
433 + cd->thread = (pthread_t)NULL;
434 pthread_exit(NULL);
435 return NULL;
436 }
@@ -489,9 +491,9 @@ void *pluginsd_main(void *ptr) {
491 }
492
493 // check if it runs already
492 - for(cd = pluginsd_root ; likely(cd) ; cd = cd->next) {
494 + for(cd = pluginsd_root ; cd ; cd = cd->next)
495 if(unlikely(strcmp(cd->filename, file->d_name) == 0)) break;
494 - }
496 +
497 if(likely(cd && !cd->obsolete)) {
498 debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is already running", cd->filename);
499 continue;
@@ -517,22 +519,19 @@ void *pluginsd_main(void *ptr) {
519 // link it
520 if(likely(pluginsd_root)) cd->next = pluginsd_root;
521 pluginsd_root = cd;
520 - }
521 - cd->obsolete = 0;
522
523 - if(unlikely(!cd->enabled)) {
523 + // it is not currently running
524 cd->obsolete = 1;
525 - continue;
526 - }
525
528 - // spawn a new thread for it
529 - if(unlikely(pthread_create(&cd->thread, NULL, pluginsd_worker_thread, cd) != 0)) {
530 - error("PLUGINSD: failed to create new thread for plugin '%s'.", cd->filename);
531 - cd->obsolete = 1;
532 - }
533 - else if(unlikely(pthread_detach(cd->thread) != 0))
534 - error("PLUGINSD: Cannot request detach of newly created thread for plugin '%s'.", cd->filename);
526 + if(cd->enabled) {
527 + // spawn a new thread for it
528 + if(unlikely(pthread_create(&cd->thread, NULL, pluginsd_worker_thread, cd) != 0))
529 + error("PLUGINSD: failed to create new thread for plugin '%s'.", cd->filename);
530
531 + else if(unlikely(pthread_detach(cd->thread) != 0))
532 + error("PLUGINSD: Cannot request detach of newly created thread for plugin '%s'.", cd->filename);
533 + }
534 + }
535 }
536
537 closedir(dir);
src/plugins_d.h
+1 -1
@@ -24,7 +24,7 @@ struct plugind {
24
25 int update_every; // the plugin default data collection frequency
26 volatile int obsolete; // do not touch this structure after setting this to 1
27 - int enabled; // if this is enabled or not
27 + volatile int enabled; // if this is enabled or not
28
29 time_t started_t;
30
src/web_client.c
-1
@@ -2097,7 +2097,6 @@ void web_client_process(struct web_client *w) {
2097
2098 error("web request to exit received.");
2099 netdata_cleanup_and_exit(0);
2100 - netdata_exit = 1;
2100 }
2101 else if(hash == hash_debug && strcmp(tok, "debug") == 0) {
2102 buffer_flush(w->response.data);