@cryptotaxi247 / netdata-1 / commits / ce21cbb0d

added support for clean exit

Costa Tsaousis (ktsaou) committed Dec 1, 2015 at 13:20 UTC ce21cbb0d656844b01b3126dd26dd28af688dc6e
1 file changed +13 -2
src/plugins_d.c
+13 -2
@@ -139,6 +139,8 @@ void *pluginsd_worker_thread(void *arg)
139 uint32_t hash;
140
141 while(likely(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL)) {
142 + if(netdata_exit) break;
143 +
144 line[PLUGINSD_LINE_MAX] = '\0';
145
146 // debug(D_PLUGINSD, "PLUGINSD: %s: %s", cd->filename, line);
@@ -384,14 +386,19 @@ void *pluginsd_worker_thread(void *arg)
386
387 // fgets() failed or loop broke
388 mypclose(fp, cd->pid);
389 + cd->pid = 0;
390 +
391 + if(netdata_exit) {
392 + cd->enabled = 0;
393 + cd->obsolete = 1;
394 + return NULL;
395 + }
396
397 if(unlikely(!count && cd->enabled)) {
398 error("PLUGINSD: '%s' (pid %d) does not generate usefull output. Waiting a bit before starting it again.", cd->fullfilename, cd->pid);
399 sleep(cd->update_every * 10);
400 }
401
393 - cd->pid = 0;
394 -
402 if(likely(cd->enabled)) sleep(cd->update_every);
403 else break;
404 }
@@ -425,6 +432,8 @@ void *pluginsd_main(void *ptr)
432 if(scan_frequency < 1) scan_frequency = 1;
433
434 while(likely(1)) {
435 + if(netdata_exit) break;
436 +
437 dir = opendir(dir_name);
438 if(unlikely(!dir)) {
439 error("Cannot open directory '%s'.", dir_name);
@@ -432,6 +441,8 @@ void *pluginsd_main(void *ptr)
441 }
442
443 while(likely((file = readdir(dir)))) {
444 + if(netdata_exit) break;
445 +
446 debug(D_PLUGINSD, "PLUGINSD: Examining file '%s'", file->d_name);
447
448 if(unlikely(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)) continue;