fix: don't reuse section names as pool names

This commit is contained in:
ngn
2024-08-18 04:12:09 +03:00
parent 41318f3b1f
commit dc6bdefe07
3 changed files with 18 additions and 9 deletions

View File

@ -21,21 +21,21 @@ config_t config = {
.pools = NULL,
};
pool_config_t *config_pool_add(char *name) {
pool_config_t *config_pool_add(char *section) {
pool_config_t *pool = malloc(sizeof(pool_config_t));
bzero(pool, sizeof(pool_config_t));
pool->name = strdup(name);
pool->next = config.pools;
config.pools = pool;
pool->section = strdup(section);
pool->next = config.pools;
config.pools = pool;
return pool;
}
bool config_pool_contains(char *name) {
bool config_pool_contains(char *section) {
pool_config_t *cur = config.pools;
while (NULL != cur) {
if (eq(cur->name, name))
if (eq(cur->section, section))
return true;
cur = cur->next;
}
@ -153,10 +153,14 @@ bool config_load(char *file) {
pool_config_t *pool = config.pools;
while (NULL != pool) {
if (NULL == pool->name)
pool->name = pool->section;
if (NULL == pool->host) {
error(_("Hostname not specified for the pool: %s"), pool->name);
return false;
}
pool = pool->next;
}
@ -172,8 +176,12 @@ void config_free() {
old = cur;
cur = cur->next;
free(old->section);
if (old->section != old->name)
free(old->name);
free(old->host);
free(old->name);
free(old->path);
free(old->dir);
free(old);
}
}