CLEANUP: config: detect double registration of a config section

In an effort to make the config parser more robust, we should validate
that everything we register is not already registered. Most cfg_register_*
functions unfortunately return void and just perform a LIST_ADDQ(), so they
will have to change for this. At least cfg_register_section() does perform
a bit of checks and is easy to check for such errors, so let's start with
this one. Future patches will definitely have to focus on the remaining
functions and ensure unicity of all config parsers.
This commit is contained in:
Willy Tarreau 2016-05-17 16:16:09 +02:00
parent 379d9c7c14
commit 5e4261b0e4
1 changed files with 7 additions and 0 deletions

View File

@ -9098,6 +9098,13 @@ int cfg_register_section(char *section_name,
{
struct cfg_section *cs;
list_for_each_entry(cs, &sections, list) {
if (strcmp(cs->section_name, section_name) == 0) {
Alert("register section '%s': already registered.\n", section_name);
return 0;
}
}
cs = calloc(1, sizeof(*cs));
if (!cs) {
Alert("register section '%s': out of memory.\n", section_name);