From: Willy Tarreau Date: Tue, 26 May 2015 08:35:50 +0000 (+0200) Subject: MEDIUM: config: reject invalid config with name duplicates X-Git-Tag: v1.6-dev2~96 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=911fa2eb8ea9565931864a0a67c9c2d72800eb61;p=thirdparty%2Fhaproxy.git MEDIUM: config: reject invalid config with name duplicates Since 1.4 we used to emit a warning when two frontends or two backends had the same name. In 1.5 we added the same warning for two peers sections. In 1.6 we added the same warning for two mailers sections. It's about time to reject such invalid configurations, the impact they have on the code complexity is huge and it is becoming a real obstacle to some improvements such as restoring servers check status across reloads. Now these errors are reported as fatal errors and will need to be fixed. Anyway, till now there was no guarantee that what was written was working as expected since the behaviour is not defined (eg: use_backend with a name used by two backends leads to undefined behaviour). Example of output : [ALERT] 145/104759 (31564) : Parsing [prx.cfg:12]: mailers section 'm' has the same name as another mailers section declared at prx.cfg:10. [ALERT] 145/104759 (31564) : Parsing [prx.cfg:16]: peers section 'p' has the same name as another peers section declared at prx.cfg:14. [ALERT] 145/104759 (31564) : Parsing [prx.cfg:21]: frontend 'f' has the same name as another frontend declared at prx.cfg:18. [ALERT] 145/104759 (31564) : Parsing [prx.cfg:27]: backend 'b' has the same name as another backend declared at prx.cfg:24. [ALERT] 145/104759 (31564) : Error(s) found in configuration file : prx.cfg [ALERT] 145/104759 (31564) : Fatal errors found in configuration. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index e08b8750b2..c74638063f 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1777,9 +1777,9 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) * combinations are allowed: */ if (strcmp(curpeers->id, args[1]) == 0) { - Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", + Alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n", file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); - err_code |= ERR_WARN; + err_code |= ERR_ALERT | ERR_FATAL; } } @@ -1978,9 +1978,9 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) * combinations are allowed: */ if (strcmp(curmailers->id, args[1]) == 0) { - Warning("Parsing [%s:%d]: mailers '%s' has same name as another mailers (declared at %s:%d).\n", + Alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n", file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); - err_code |= ERR_WARN; + err_code |= ERR_ALERT | ERR_FATAL; } } @@ -2150,10 +2150,10 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && (rc != (PR_CAP_BE|PR_CAP_RS) || curproxy->cap != (PR_CAP_FE|PR_CAP_RS))) { - Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", + Alert("Parsing [%s:%d]: %s '%s' has the same name as another %s declared at %s:%d.\n", file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), curproxy->conf.file, curproxy->conf.line); - err_code |= ERR_WARN; + err_code |= ERR_ALERT | ERR_FATAL; } }