tc_device_compare
};
-#define tc_device_index_add(st) avl_insert(&tc_device_root_index, (avl *)(st))
-#define tc_device_index_del(st) avl_remove(&tc_device_root_index, (avl *)(st))
+#define tc_device_index_add(st) (struct tc_device *)avl_insert(&tc_device_root_index, (avl *)(st))
+#define tc_device_index_del(st) (struct tc_device *)avl_remove(&tc_device_root_index, (avl *)(st))
static inline struct tc_device *tc_device_index_find(const char *id, uint32_t hash) {
struct tc_device tmp;
else return strcmp(((struct tc_class *)a)->id, ((struct tc_class *)b)->id);
}
-#define tc_class_index_add(st, rd) avl_insert(&((st)->classes_index), (avl *)(rd))
-#define tc_class_index_del(st, rd) avl_remove(&((st)->classes_index), (avl *)(rd))
+#define tc_class_index_add(st, rd) (struct tc_class *)avl_insert(&((st)->classes_index), (avl *)(rd))
+#define tc_class_index_del(st, rd) (struct tc_class *)avl_remove(&((st)->classes_index), (avl *)(rd))
static inline struct tc_class *tc_class_index_find(struct tc_device *st, const char *id, uint32_t hash) {
struct tc_class tmp;
debug(D_TC_LOOP, "Removing from device '%s' class '%s', parentid '%s', leafid '%s', seen=%d", n->id, c->id, c->parentid?c->parentid:"", c->leafid?c->leafid:"", c->seen);
- tc_class_index_del(n, c);
+ if(unlikely(tc_class_index_del(n, c) != c))
+ error("plugin_tc: INTERNAL ERROR: attempt remove class '%s' from device '%s': removed a different calls", c->id, n->id);
freez(c->id);
freez(c->name);
snprintfz(var_name, CONFIG_MAX_NAME, "dropped packets chart for %s", d->id);
d->enabled_dropped = config_get_boolean_ondemand("plugin:tc", var_name, enable_dropped);
- snprintfz(var_name, CONFIG_MAX_NAME, "dropped tokens chart for %s", d->id);
+ snprintfz(var_name, CONFIG_MAX_NAME, "tokens chart for %s", d->id);
d->enabled_tokens = config_get_boolean_ondemand("plugin:tc", var_name, enable_tokens);
- snprintfz(var_name, CONFIG_MAX_NAME, "dropped ctokens chart for %s", d->id);
+ snprintfz(var_name, CONFIG_MAX_NAME, "ctokens chart for %s", d->id);
d->enabled_ctokens = config_get_boolean_ondemand("plugin:tc", var_name, enable_ctokens);
}
}
else {
debug(D_TC_LOOP, "TC: Updating chart for device '%s'", d->name?d->name:d->id);
- rrdset_next_plugins(d->st_bytes);
+ rrdset_next(d->st_bytes);
if(unlikely(d->name_updated && d->name && strcmp(d->id, d->name) != 0)) {
rrdset_set_name(d->st_bytes, d->name);
}
else {
debug(D_TC_LOOP, "TC: Updating _packets chart for device '%s'", d->name?d->name:d->id);
- rrdset_next_plugins(d->st_packets);
+ rrdset_next(d->st_packets);
// FIXME
// update the family
}
else {
debug(D_TC_LOOP, "TC: Updating _dropped chart for device '%s'", d->name?d->name:d->id);
- rrdset_next_plugins(d->st_dropped);
+ rrdset_next(d->st_dropped);
// FIXME
// update the family
}
else {
debug(D_TC_LOOP, "TC: Updating _tokens chart for device '%s'", d->name?d->name:d->id);
- rrdset_next_plugins(d->st_tokens);
+ rrdset_next(d->st_tokens);
// FIXME
// update the family
}
else {
debug(D_TC_LOOP, "TC: Updating _ctokens chart for device '%s'", d->name?d->name:d->id);
- rrdset_next_plugins(d->st_ctokens);
+ rrdset_next(d->st_ctokens);
// FIXME
// update the family
d->enabled = (char)-1;
avl_init(&d->classes_index, tc_class_compare);
- tc_device_index_add(d);
+ if(unlikely(tc_device_index_add(d) != d))
+ error("plugin_tc: INTERNAL ERROR: removing device '%s' removed a different device.", d->id);
if(!tc_device_root) {
tc_device_root = d;
c->leaf_hash = simple_hash(c->leafid);
}
- tc_class_index_add(n, c);
+ if(unlikely(tc_class_index_add(n, c) != c))
+ error("plugin_tc: INTERNAL ERROR: attempt index class '%s' on device '%s': already exists", c->id, n->id);
}
c->seen = 1;
else tc_device_root = n->prev;
}
- tc_device_index_del(n);
+ if(unlikely(tc_device_index_del(n) != n))
+ error("plugin_tc: INTERNAL ERROR: removing device '%s' removed a different device.", n->id);
while(n->classes) tc_class_free(n, n->classes);
pid_t tc_child_pid = 0;
void *tc_main(void *ptr) {
- (void)ptr;
+ struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
info("TC thread created with task id %d", gettid());
fp = mypopen(buffer, &tc_child_pid);
if(unlikely(!fp)) {
error("TC: Cannot popen(\"%s\", \"r\").", buffer);
- pthread_exit(NULL);
- return NULL;
+ goto cleanup;
}
while(fgets(buffer, TC_LINE_MAX, fp) != NULL) {
if(unlikely(netdata_exit)) {
tc_device_free_all();
- pthread_exit(NULL);
- return NULL;
+ goto cleanup;
}
if(code == 1 || code == 127) {
error("TC: tc-qos-helper.sh exited with code %d. Disabling it.", code);
tc_device_free_all();
- pthread_exit(NULL);
- return NULL;
+ goto cleanup;
}
sleep((unsigned int) rrd_update_every);
}
+cleanup:
+ info("TC thread exiting");
+
+ static_thread->enabled = 0;
+ static_thread->thread = NULL;
pthread_exit(NULL);
return NULL;
}