]> arthur.barton.de Git - netdata.git/commitdiff
detect duplicate cgroups; fixes #797
authorCosta Tsaousis <costa@tsaousis.gr>
Sun, 21 Aug 2016 09:33:35 +0000 (12:33 +0300)
committerCosta Tsaousis <costa@tsaousis.gr>
Sun, 21 Aug 2016 09:33:35 +0000 (12:33 +0300)
src/sys_fs_cgroup.c

index 616b806f678ef3136a573ea39cc7db15c3be7821..82ae5c7235a367ccd2a4e498dc2634f2bf672924 100644 (file)
@@ -168,6 +168,8 @@ struct cgroup {
     uint32_t hash;
 
     char *chart_id;
+    uint32_t hash_chart;
+
     char *chart_title;
 
     struct cpuacct_stat cpuacct_stat;
@@ -682,6 +684,8 @@ struct cgroup *cgroup_add(const char *id) {
     cg->hash = simple_hash(cg->id);
 
     cg->chart_id = strdupz(chart_id);
+    cg->hash_chart = simple_hash(cg->chart_id);
+
     cg->chart_title = strdupz(chart_id);
 
     if(!cgroup_root)
@@ -702,6 +706,14 @@ struct cgroup *cgroup_add(const char *id) {
     snprintfz(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
     cg->enabled = config_get_boolean("plugin:cgroups", option, def);
 
+    struct cgroup *t;
+    for(t = cgroup_root; t ; t = t->next) {
+        if(t != cg && t->hash_chart == cg->hash_chart && !strcmp(t->chart_id, cg->chart_id) && t->enabled) {
+            error("Control group with chart id '%s' already exists and is enabled. Disabling cgroup '%s'.", cg->chart_id, cg->id);
+            cg->enabled = 0;
+        }
+    }
+
     debug(D_CGROUP, "Added cgroup '%s' with chart id '%s' and title '%s' as %s (default was %s)", cg->id, cg->chart_id, cg->chart_title, (cg->enabled)?"enabled":"disabled", (def)?"enabled":"disabled");
 
     return cg;