From 816eb54e9bdccc0251b35142b1dbc6381f737e1a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 4 Nov 2007 07:04:43 +0100 Subject: [PATCH] [MINOR] adjust error messages about conflicting proxies It's not easy to report useful information to help the user quickly fix a configuration. This patch : - removes the word "listener" in favor of "proxy" as it has been used since the beginning ; - ensures that the same function (hence the same words) will be used to report capabilities of a proxy being declared and an existing proxy ; - avoid the term "conflicting capabilities" in favor of "overlapping capabilities" which is more exact. - just report that the same name is reused in case of warnings --- include/proto/proxy.h | 11 ++++++++++- src/cfgparse.c | 4 ++-- src/proxy.c | 31 +++++++++++++++---------------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/include/proto/proxy.h b/include/proto/proxy.h index 839cce5812..a0c86cb877 100644 --- a/include/proto/proxy.h +++ b/include/proto/proxy.h @@ -33,10 +33,19 @@ void pause_proxy(struct proxy *p); void pause_proxies(void); void listen_proxies(void); -const char *proxy_type_str(struct proxy *proxy); +const char *proxy_cap_str(int cap); const char *proxy_mode_str(int mode); struct proxy *findproxy(const char *name, int mode, int cap); +/* + * This function returns a string containing the type of the proxy in a format + * suitable for error messages, from its capabilities. + */ +static inline const char *proxy_type_str(struct proxy *proxy) +{ + return proxy_cap_str(proxy->cap); +} + #endif /* _PROTO_PROXY_H */ /* diff --git a/src/cfgparse.c b/src/cfgparse.c index fc333bfbbf..0df66daae3 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -539,8 +539,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args) if (!strcmp(curproxy->id, args[1]) && (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]: duplicated proxy '%s' with conflicting capabilities: %s/%s!\n", - file, linenum, args[1], proxy_type_str(curproxy), args[0]); + Warning("Parsing [%s:%d]: %s '%s' has same name as another %s.\n", + file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy)); } } diff --git a/src/proxy.c b/src/proxy.c index 1f5481868f..feb93c2f3a 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -37,29 +37,28 @@ int listeners; /* # of listeners */ struct proxy *proxy = NULL; /* list of all existing proxies */ /* - * This function returns a string containing the type of the proxy in a format - * suitable for error messages, from its capabilities. + * This function returns a string containing a name describing capabilities to + * report comprehensible error messages. Specifically, it will return the words + * "frontend", "backend", "ruleset" when appropriate, or "proxy" for all other + * cases including the proxies declared in "listen" mode. */ -const char *proxy_type_str(struct proxy *proxy) +const char *proxy_cap_str(int cap) { - int cap = proxy->cap; - if ((cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) - return "listener"; - else if (cap & PR_CAP_FE) - return "frontend"; - else if (cap & PR_CAP_BE) - return "backend"; - else if (cap & PR_CAP_RS) - return "ruleset"; - else - return "proxy"; + if ((cap & PR_CAP_LISTEN) != PR_CAP_LISTEN) { + if (cap & PR_CAP_FE) + return "frontend"; + else if (cap & PR_CAP_BE) + return "backend"; + else if (cap & PR_CAP_RS) + return "ruleset"; + } + return "proxy"; } /* * This function returns a string containing the mode of the proxy in a format * suitable for error messages. */ - const char *proxy_mode_str(int mode) { if (mode == PR_MODE_TCP) @@ -98,7 +97,7 @@ struct proxy *findproxy(const char *name, int mode, int cap) { continue; } - Alert("Refusing to use duplicated proxy '%s' with conflicting capabilities: %s/%s!\n", + Alert("Refusing to use duplicated proxy '%s' with overlapping capabilities: %s/%s!\n", name, proxy_type_str(curproxy), proxy_type_str(target)); return NULL;