#include "rrd.h"
#include "popen.h"
#include "plugin_tc.h"
+#include "main.h"
#define RRD_TYPE_TC "tc"
#define RRD_TYPE_TC_LEN strlen(RRD_TYPE_TC)
avl_tree classes_index;
struct tc_class *classes;
+
+ struct tc_device *next;
+ struct tc_device *prev;
};
+struct tc_device *tc_device_root = NULL;
+
// ----------------------------------------------------------------------------
// tc_device index
if(c->next) c->next->prev = c->prev;
if(c->prev) c->prev->next = c->next;
- if(n->classes == c) n->classes = c->next;
+ if(n->classes == c) {
+ if(c->next) n->classes = c->next;
+ else n->classes = c->prev;
+ }
tc_class_index_del(n, c);
pthread_rwlock_init(&d->classes_index.rwlock, NULL);
tc_device_index_add(d);
+
+ if(!tc_device_root) {
+ tc_device_root = d;
+ }
+ else {
+ d->next = tc_device_root;
+ tc_device_root->prev = d;
+ tc_device_root = d;
+ }
}
return(d);
return(c);
}
-/*
+
static void tc_device_free(struct tc_device *n)
{
+ if(n->next) n->next->prev = n->prev;
+ if(n->prev) n->prev->next = n->next;
+ if(tc_device_root == n) {
+ if(n->next) tc_device_root = n->next;
+ else tc_device_root = n->prev;
+ }
+
tc_device_index_del(n);
while(n->classes) tc_class_free(n, n->classes);
free(n);
}
-*/
+
+static void tc_device_free_all()
+{
+ while(tc_device_root)
+ tc_device_free(tc_device_root);
+}
#define MAX_WORDS 20
}
while(fgets(buffer, TC_LINE_MAX, fp) != NULL) {
+ if(netdata_exit) break;
+
buffer[TC_LINE_MAX] = '\0';
// debug(D_TC_LOOP, "TC: read '%s'", buffer);
class = NULL;
}
+ if(netdata_exit) {
+ tc_device_free_all();
+ return NULL;
+ }
+
sleep(rrd_update_every);
}