Skip to content

Commit

Permalink
legiond: refactor init_config
Browse files Browse the repository at this point in the history
  • Loading branch information
st0nie committed Apr 18, 2024
1 parent f43ba2f commit 20e2cd4
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions extra/service/legiond/modules/parseconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0

static bool reload = false;

static int handler(void *user, const char *section, const char *name,
const char *value)
{
Expand Down Expand Up @@ -58,51 +60,34 @@ static int handler(void *user, const char *section, const char *name,

static void reset(const char *p)
{
if (p) {
if (p && reload) {
free((char *)p);
}
p = NULL;
}

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;
}
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);

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;
if (!reload)
reload = true;
}

extern int parseconf(LEGIOND_CONFIG *config)
Expand Down

0 comments on commit 20e2cd4

Please sign in to comment.