]> arthur.barton.de Git - netdata.git/commitdiff
added support for clean exit
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 1 Dec 2015 11:20:56 +0000 (13:20 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 1 Dec 2015 11:20:56 +0000 (13:20 +0200)
src/plugins_d.c

index f5cdc60a37882d0ee86e33ed736ccad7133040ed..b99f668d6d865a204af0075c9b626465129bf5f0 100755 (executable)
@@ -139,6 +139,8 @@ void *pluginsd_worker_thread(void *arg)
                uint32_t hash;
 
                while(likely(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL)) {
+                       if(netdata_exit) break;
+
                        line[PLUGINSD_LINE_MAX] = '\0';
 
                        // debug(D_PLUGINSD, "PLUGINSD: %s: %s", cd->filename, line);
@@ -384,14 +386,19 @@ void *pluginsd_worker_thread(void *arg)
 
                // fgets() failed or loop broke
                mypclose(fp, cd->pid);
+               cd->pid = 0;
+
+               if(netdata_exit) {
+                       cd->enabled = 0;
+                       cd->obsolete = 1;
+                       return NULL;
+               }
 
                if(unlikely(!count && cd->enabled)) {
                        error("PLUGINSD: '%s' (pid %d) does not generate usefull output. Waiting a bit before starting it again.", cd->fullfilename, cd->pid);
                        sleep(cd->update_every * 10);
                }
 
-               cd->pid = 0;
-
                if(likely(cd->enabled)) sleep(cd->update_every);
                else break;
        }
@@ -425,6 +432,8 @@ void *pluginsd_main(void *ptr)
        if(scan_frequency < 1) scan_frequency = 1;
 
        while(likely(1)) {
+               if(netdata_exit) break;
+
                dir = opendir(dir_name);
                if(unlikely(!dir)) {
                        error("Cannot open directory '%s'.", dir_name);
@@ -432,6 +441,8 @@ void *pluginsd_main(void *ptr)
                }
 
                while(likely((file = readdir(dir)))) {
+                       if(netdata_exit) break;
+
                        debug(D_PLUGINSD, "PLUGINSD: Examining file '%s'", file->d_name);
 
                        if(unlikely(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)) continue;