fix(cgroups.plugin): remove "enable cgroup X" config option on cgroup deletion (#12746)
Ilya Mashchenko committed
Apr 25, 2022 at 16:59 UTC
7b7fbd6086207cf05a18fe1344833edfe03a8264
3 files changed
+53
collectors/cgroups.plugin/sys_fs_cgroup.c
+3
@@ -2371,6 +2371,9 @@ static inline void cleanup_all_cgroups() {
2371
else
2372
last->discovered_next = cg->discovered_next;
2373
2374
+ char option[FILENAME_MAX + 1];
2375
+ snprintfz(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
2376
+ config_section_option_destroy("plugin:cgroups", option);
2377
cgroup_free(cg);
2378
2379
if(!last)
daemon/common.h
+2
@@ -27,6 +27,8 @@
27
28
#define config_generate(buffer, only_changed) appconfig_generate(&netdata_config, buffer, only_changed)
29
30
+#define config_section_option_destroy(section, name) appconfig_section_option_destroy_non_loaded(&netdata_config, section, name)
31
+
32
// ----------------------------------------------------------------------------
33
// netdata include files
34
libnetdata/config/appconfig.c
+48
@@ -257,6 +257,54 @@ void appconfig_section_destroy_non_loaded(struct config *root, const char *secti
257
freez(co);
258
}
259
260
+void appconfig_section_option_destroy_non_loaded(struct config *root, const char *section, const char *name)
261
+{
262
+ debug(D_CONFIG, "Destroying section option '%s -> %s'.", section, name);
263
+
264
+ struct section *co;
265
+ co = appconfig_section_find(root, section);
266
+ if (!co) {
267
+ error("Could not destroy section option '%s -> %s'. The section not found.", section, name);
268
+ return;
269
+ }
270
+
271
+ config_section_wrlock(co);
272
+
273
+ struct config_option *cv;
274
+
275
+ cv = appconfig_option_index_find(co, name, simple_hash(name));
276
+
277
+ if (cv && cv->flags & CONFIG_VALUE_LOADED) {
278
+ config_section_unlock(co);
279
+ return;
280
+ }
281
+
282
+ if (unlikely(!(cv && appconfig_option_index_del(co, cv)))) {
283
+ config_section_unlock(co);
284
+ error("Could not destroy section option '%s -> %s'. The option not found.", section, name);
285
+ return;
286
+ }
287
+
288
+ if (co->values == cv) {
289
+ co->values = co->values->next;
290
+ } else {
291
+ struct config_option *cv_cur = co->values, *cv_prev = NULL;
292
+ while (cv_cur && cv_cur != cv) {
293
+ cv_prev = cv_cur;
294
+ cv_cur = cv_cur->next;
295
+ }
296
+ if (cv_cur) {
297
+ cv_prev->next = cv_cur->next;
298
+ }
299
+ }
300
+
301
+ freez(cv->value);
302
+ freez(cv->name);
303
+ freez(cv);
304
+
305
+ config_section_unlock(co);
306
+ return;
307
+}
308
309
// ----------------------------------------------------------------------------
310
// config name-value methods