From f43ba2fe428fe5d2c779d5b9a0cca66ec977cfec Mon Sep 17 00:00:00 2001 From: ston Date: Sun, 14 Apr 2024 17:02:30 +0800 Subject: [PATCH] legiond: reset config on reload --- extra/service/legiond/modules/parseconf.c | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/extra/service/legiond/modules/parseconf.c b/extra/service/legiond/modules/parseconf.c index 77b4c16..e113074 100644 --- a/extra/service/legiond/modules/parseconf.c +++ b/extra/service/legiond/modules/parseconf.c @@ -56,8 +56,58 @@ static int handler(void *user, const char *section, const char *name, return 1; } +static void reset(const char *p) +{ + if (p) { + free((char *)p); + } +} + +static void init_config(LEGIOND_CONFIG *config) +{ + static bool reload = false; + config->fan_control = false; + config->cpu_control = false; + if (reload) { + reset(config->gpu_control); + reset(config->cpu_ac_q); + reset(config->cpu_bat_q); + reset(config->cpu_ac_b); + reset(config->cpu_bat_b); + reset(config->cpu_ac_bp); + reset(config->cpu_bat_bp); + reset(config->cpu_ac_p); + reset(config->gpu_tdp_ac_q); + reset(config->gpu_tdp_bat_q); + reset(config->gpu_tdp_ac_b); + reset(config->gpu_tdp_bat_b); + reset(config->gpu_tdp_ac_bp); + reset(config->gpu_tdp_bat_bp); + reset(config->gpu_tdp_ac_p); + } else { + reload = true; + } + + config->gpu_control = NULL; + config->cpu_ac_q = NULL; + config->cpu_bat_q = NULL; + config->cpu_ac_b = NULL; + config->cpu_bat_b = NULL; + config->cpu_ac_bp = NULL; + config->cpu_bat_bp = NULL; + config->cpu_ac_p = NULL; + config->gpu_tdp_ac_q = NULL; + config->gpu_tdp_bat_q = NULL; + config->gpu_tdp_ac_b = NULL; + config->gpu_tdp_bat_b = NULL; + config->gpu_tdp_ac_bp = NULL; + config->gpu_tdp_bat_bp = NULL; + config->gpu_tdp_ac_p = NULL; +} + extern int parseconf(LEGIOND_CONFIG *config) { + init_config(config); if (ini_parse(config_path, handler, config)) { printf("Unable to parse config\n"); return 1;