]> arthur.barton.de Git - netdata.git/blobdiff - src/plugin_tc.c
Merge pull request #17 from alonbl/build
[netdata.git] / src / plugin_tc.c
index 708da0192e8d003d5c89f6cb53fbf96ddfbf6e28..8f932011dad62f398290e1a6d654a9c2b7d98206 100755 (executable)
@@ -1,12 +1,15 @@
-#include <inttypes.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
 
 #include "avl.h"
 #include "log.h"
 #include "common.h"
-#include "config.h"
+#include "appconfig.h"
 #include "rrd.h"
 #include "popen.h"
 #include "plugin_tc.h"
@@ -237,23 +240,23 @@ static void tc_device_commit(struct tc_device *d)
                        if(!c->updated) continue;
 
                        if(c->isleaf && c->hasparent) {
-                               if(rrddim_set(st, c->id, c->bytes) != 0) {
+                               RRDDIM *rd = rrddim_find(st, c->id);
+
+                               if(!rd) {
                                        debug(D_TC_LOOP, "TC: Adding to chart '%s', dimension '%s'", st->id, c->id, c->name);
                                        
                                        // new class, we have to add it
-                                       rrddim_add(st, c->id, c->name?c->name:c->id, 8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
-                                       rrddim_set(st, c->id, c->bytes);
+                                       rd = rrddim_add(st, c->id, c->name?c->name:c->id, 8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
                                }
                                else debug(D_TC_LOOP, "TC: Updating chart '%s', dimension '%s'", st->id, c->id);
 
+                               rrddim_set_by_pointer(st, rd, c->bytes);
+
                                // if it has a name, different to the id
                                if(c->name) {
                                        // update the rrd dimension with the new name
-                                       RRDDIM *rd = rrddim_find(st, c->id);
-                                       if(rd) {
-                                               debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", st->id, rd->id, c->name);
-                                               rrddim_set_name(st, rd, c->name);
-                                       }
+                                       debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", st->id, rd->id, c->name);
+                                       rrddim_set_name(st, rd, c->name);
 
                                        free(c->name);
                                        c->name = NULL;
@@ -437,6 +440,8 @@ void *tc_main(void *ptr)
 {
        if(ptr) { ; }
 
+       info("TC thread created with task id %d", gettid());
+
        if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
                error("Cannot set pthread cancel type to DEFERRED.");
 
@@ -580,7 +585,8 @@ void *tc_main(void *ptr)
                        //      debug(D_TC_LOOP, "IGNORED line");
                        //}
                }
-               mypclose(fp);
+               mypclose(fp, tc_child_pid);
+               tc_child_pid = 0;
 
                if(device) {
                        // tc_device_free(device);