@cryptotaxi247 / netdata-1 / commits / fcce8d3f8

better handling when tc-all.sh exits

Costa Tsaousis (ktsaou) committed Apr 12, 2014 at 03:36 UTC fcce8d3f805ddbc9c7b642b1d12ff22e3fc8514d
2 files changed +23 -2
netdata.c
+12 -2
@@ -3368,7 +3368,11 @@ void *tc_main(void *ptr)
3368 }
3369 }
3370 else if(strcmp(p, "BEGIN") == 0) {
3371 - if(device) tc_device_free(device);
3371 + if(device) {
3372 + tc_device_free(device);
3373 + device = NULL;
3374 + class = NULL;
3375 + }
3376
3377 p = strsep(&b, " \n");
3378 if(p && *p) device = tc_device_create(p);
@@ -3427,7 +3431,13 @@ void *tc_main(void *ptr)
3431 }
3432 pclose(fp);
3433
3430 - sleep(1);
3434 + if(device) {
3435 + tc_device_free(device);
3436 + device = NULL;
3437 + class = NULL;
3438 + }
3439 +
3440 + sleep(update_every);
3441 }
3442
3443 return NULL;
tc-all.sh
+11
@@ -48,12 +48,21 @@ all_devices() {
48 done
49 }
50
51 +# update devices and class names
52 +# once every 2 minutes
53 names_every=$((120 / sleep_time))
54 +
55 +# exit this script every hour
56 +# it will be restarted automatically
57 +exit_after=$((3600 / sleep_time))
58 +
59 c=0
60 +gc=0
61 while [ 1 ]
62 do
63 fix_names=
64 c=$((c + 1))
65 + gc=$((gc + 1))
66
67 if [ $c -le 1 -o $c -ge $names_every ]
68 then
@@ -67,5 +76,7 @@ do
76 show_tc $d
77 done
78
79 + [ $gc -gt $exit_after ] && exit 0
80 +
81 sleep $sleep_time
82 done