From ef00b500110c49a275e5ddfa622e646fd5cb7e41 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 7 Jan 2007 02:40:09 +0100 Subject: [PATCH] [MINOR] try to guess server check port when unset When a server has no port specified and there is a check enabled on it, the check is disabled because the port is unknown. However, people expect the "listen" line to set the check port just like it sets the server's port. Now, if a port is specified in the listen or in the first bind and nowhere else, it will be used for the checks as well. --- src/cfgparse.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cfgparse.c b/src/cfgparse.c index c49ce218a..b385781b3 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1236,6 +1236,21 @@ int cfg_parse_listen(const char *file, int linenum, char **args) if (do_check) { if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) newsrv->check_port = realport; /* by default */ + if (!newsrv->check_port) { + /* not yet valid, because no port was set on + * the server either. We'll check if we have + * a known port on the first listener. + */ + struct listener *l; + l = curproxy->listen; + if (l) { + int port; + port = (l->addr.ss_family == AF_INET6) + ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) + : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); + newsrv->check_port = port; + } + } if (!newsrv->check_port) { Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", file, linenum, newsrv->id);