@cryptotaxi247 / netdata-1 / commits / def60e69a

detect duplicate cgroups; fixes #797

Costa Tsaousis committed Aug 21, 2016 at 12:33 UTC def60e69a5c08b1d31dcafece44e19cab6a7a406
1 file changed +12
src/sys_fs_cgroup.c
+12
@@ -168,6 +168,8 @@ struct cgroup {
168 uint32_t hash;
169
170 char *chart_id;
171 + uint32_t hash_chart;
172 +
173 char *chart_title;
174
175 struct cpuacct_stat cpuacct_stat;
@@ -682,6 +684,8 @@ struct cgroup *cgroup_add(const char *id) {
684 cg->hash = simple_hash(cg->id);
685
686 cg->chart_id = strdupz(chart_id);
687 + cg->hash_chart = simple_hash(cg->chart_id);
688 +
689 cg->chart_title = strdupz(chart_id);
690
691 if(!cgroup_root)
@@ -702,6 +706,14 @@ struct cgroup *cgroup_add(const char *id) {
706 snprintfz(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
707 cg->enabled = config_get_boolean("plugin:cgroups", option, def);
708
709 + struct cgroup *t;
710 + for(t = cgroup_root; t ; t = t->next) {
711 + if(t != cg && t->hash_chart == cg->hash_chart && !strcmp(t->chart_id, cg->chart_id) && t->enabled) {
712 + error("Control group with chart id '%s' already exists and is enabled. Disabling cgroup '%s'.", cg->chart_id, cg->id);
713 + cg->enabled = 0;
714 + }
715 + }
716 +
717 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");
718
719 return cg;