summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2022-04-25 16:59:54 +0300
committerGitHub <noreply@github.com>2022-04-25 16:59:54 +0300
commit7b7fbd6086207cf05a18fe1344833edfe03a8264 (patch)
treec9a74f76708fd182eff93783e9da381fc4418d4c
parent5e8b714acc6a385013c7ddda596f335b298284b6 (diff)
fix(cgroups.plugin): remove "enable cgroup X" config option on cgroup deletion (#12746)
-rw-r--r--collectors/cgroups.plugin/sys_fs_cgroup.c3
-rw-r--r--daemon/common.h2
-rw-r--r--libnetdata/config/appconfig.c48
3 files changed, 53 insertions, 0 deletions
diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.c b/collectors/cgroups.plugin/sys_fs_cgroup.c
index 3e0154dadc..9ba249ca60 100644
--- a/collectors/cgroups.plugin/sys_fs_cgroup.c
+++ b/collectors/cgroups.plugin/sys_fs_cgroup.c
@@ -2371,6 +2371,9 @@ static inline void cleanup_all_cgroups() {
else
last->discovered_next = cg->discovered_next;
+ char option[FILENAME_MAX + 1];
+ snprintfz(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
+ config_section_option_destroy("plugin:cgroups", option);
cgroup_free(cg);
if(!last)
diff --git a/daemon/common.h b/daemon/common.h
index e11a6d6b6c..2a45ffe70e 100644
--- a/daemon/common.h
+++ b/daemon/common.h
@@ -27,6 +27,8 @@
#define config_generate(buffer, only_changed) appconfig_generate(&netdata_config, buffer, only_changed)
+#define config_section_option_destroy(section, name) appconfig_section_option_destroy_non_loaded(&netdata_config, section, name)
+
// ----------------------------------------------------------------------------
// netdata include files
diff --git a/libnetdata/config/appconfig.c b/libnetdata/config/appconfig.c
index 0daa6e5e48..b710190d0a 100644
--- a/libnetdata/config/appconfig.c
+++ b/libnetdata/config/appconfig.c
@@ -257,6 +257,54 @@ void appconfig_section_destroy_non_loaded(struct config *root, const char *secti
freez(co);
}
+void appconfig_section_option_destroy_non_loaded(struct config *root, const char *section, const char *name)
+{
+ debug(D_CONFIG, "Destroying section option '%s -> %s'.", section, name);
+
+ struct section *co;
+ co = appconfig_section_find(root, section);
+ if (!co) {
+ error("Could not destroy section option '%s -> %s'. The section not found.", section, name);
+ return;
+ }
+
+ config_section_wrlock(co);
+
+ struct config_option *cv;
+
+ cv = appconfig_option_index_find(co, name, simple_hash(name));
+
+ if (cv && cv->flags & CONFIG_VALUE_LOADED) {
+ config_section_unlock(co);
+ return;
+ }
+
+ if (unlikely(!(cv && appconfig_option_index_del(co, cv)))) {
+ config_section_unlock(co);
+ error("Could not destroy section option '%s -> %s'. The option not found.", section, name);
+ return;
+ }
+
+ if (co->values == cv) {
+ co->values = co->values->next;
+ } else {
+ struct config_option *cv_cur = co->values, *cv_prev = NULL;
+ while (cv_cur && cv_cur != cv) {
+ cv_prev = cv_cur;
+ cv_cur = cv_cur->next;
+ }
+ if (cv_cur) {
+ cv_prev->next = cv_cur->next;
+ }
+ }
+
+ freez(cv->value);
+ freez(cv->name);
+ freez(cv);
+
+ config_section_unlock(co);
+ return;
+}
// ----------------------------------------------------------------------------
// config name-value methods