]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] config: improve error reporting when checking configuration
authorWilly Tarreau <w@1wt.eu>
Thu, 23 Jul 2009 11:36:36 +0000 (13:36 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 26 Jul 2009 15:41:10 +0000 (17:41 +0200)
Do not exit early at the first error found while checking configuration
validity. This particularly helps spotting multiple wrong tracked server
names at once.
(cherry picked from commit bb9250104fdf1096b708181c82172df737341a95)

src/cfgparse.c
src/haproxy.c

index 8227a892b16761ef4be38fd00ee395012186be83..d8000e175e5f45ea61a976c86b722a98338fd912 100644 (file)
@@ -3590,11 +3590,21 @@ int readcfgfile(const char *file)
        return err_code;
 }
 
+/*
+ * Returns the error code, 0 if OK, or any combination of :
+ *  - ERR_ABORT: must abort ASAP
+ *  - ERR_FATAL: we can continue parsing but not start the service
+ *  - ERR_WARN: a warning has been emitted
+ *  - ERR_ALERT: an alert has been emitted
+ * Only the two first ones can stop processing, the two others are just
+ * indicators.
+ */
 int check_config_validity()
 {
        int cfgerr = 0;
        struct proxy *curproxy = NULL;
        struct server *newsrv = NULL;
+       int err_code = 0;
 
        /*
         * Now, check for the integrity of all that we have collected.
@@ -3618,7 +3628,8 @@ int check_config_validity()
 
        if ((curproxy = proxy) == NULL) {
                Alert("config : no <listen> line. Nothing to do !\n");
-               goto err;
+               err_code |= ERR_ALERT | ERR_FATAL;
+               goto out;
        }
 
        while (curproxy != NULL) {
@@ -3682,6 +3693,7 @@ int check_config_validity()
                                else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) {
                                        Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
                                                proxy_type_str(curproxy), curproxy->id);
+                                       err_code |= ERR_WARN;
                                }
                        }
                        else if (!(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) &&
@@ -3699,6 +3711,7 @@ int check_config_validity()
                        curproxy->options &= ~PR_O_DISABLE404;
                        Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
                                "disable-on-404", proxy_type_str(curproxy), curproxy->id);
+                       err_code |= ERR_WARN;
                }
 
                /* if a default backend was specified, let's find it */
@@ -3713,6 +3726,7 @@ int check_config_validity()
                        } else if (target == curproxy) {
                                Alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
                                        curproxy->id, curproxy->defbe.name);
+                               cfgerr++;
                        } else {
                                free(curproxy->defbe.name);
                                curproxy->defbe.be = target;
@@ -3789,6 +3803,7 @@ int check_config_validity()
                                "   | with such a configuration. To fix this, please ensure that all following\n"
                                "   | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
                                proxy_type_str(curproxy), curproxy->id);
+                       err_code |= ERR_WARN;
                }
 
                /* Historically, the tarpit and queue timeouts were inherited from contimeout.
@@ -3885,7 +3900,7 @@ int check_config_validity()
                        if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) {
                                Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
                                      proxy_type_str(curproxy), curproxy->id);
-                               goto err;
+                               cfgerr++;
                        }
                        newsrv = newsrv->next;
                }
@@ -3909,7 +3924,7 @@ int check_config_validity()
                        } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) {
                                Alert("config : %s '%s' : fullconn is mandatory when minconn is set on a server.\n",
                                      proxy_type_str(curproxy), curproxy->id);
-                               goto err;
+                               cfgerr++;
                        }
 
                        if (newsrv->trackit) {
@@ -3933,7 +3948,8 @@ int check_config_validity()
                                                Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
                                                        proxy_type_str(curproxy), curproxy->id,
                                                        newsrv->id, pname);
-                                               return -1;
+                                               cfgerr++;
+                                               goto next_srv;
                                        }
                                } else
                                        px = curproxy;
@@ -3943,7 +3959,8 @@ int check_config_validity()
                                        Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
                                                proxy_type_str(curproxy), curproxy->id,
                                                newsrv->id, sname);
-                                       return -1;
+                                       cfgerr++;
+                                       goto next_srv;
                                }
 
                                if (!(srv->state & SRV_CHECKED)) {
@@ -3951,7 +3968,8 @@ int check_config_validity()
                                                "tracing as it does not have checks enabled.\n",
                                                proxy_type_str(curproxy), curproxy->id,
                                                newsrv->id, px->id, srv->id);
-                                       return -1;
+                                       cfgerr++;
+                                       goto next_srv;
                                }
 
                                if (curproxy != px &&
@@ -3960,7 +3978,8 @@ int check_config_validity()
                                                "tracing: disable-on-404 option inconsistency.\n",
                                                proxy_type_str(curproxy), curproxy->id,
                                                newsrv->id, px->id, srv->id);
-                                       return -1;
+                                       cfgerr++;
+                                       goto next_srv;
                                }
 
                                newsrv->tracked = srv;
@@ -3969,7 +3988,7 @@ int check_config_validity()
 
                                free(newsrv->trackit);
                        }
-
+               next_srv:
                        newsrv = newsrv->next;
                }
 
@@ -3998,11 +4017,6 @@ int check_config_validity()
                curproxy = curproxy->next;
        }
 
-       if (cfgerr > 0) {
-               Alert("Errors found in configuration, aborting.\n");
-               goto err;
-       }
-
        /*
         * Recount currently required checks.
         */
@@ -4019,9 +4033,10 @@ int check_config_validity()
                                global.last_checks |= cfg_opts2[optnum].checks;
        }
 
-       return 0;
- err:
-       return -1;
+       if (cfgerr > 0)
+               err_code |= ERR_ALERT | ERR_FATAL;
+ out:
+       return err_code;
 }
 
 /*
index 8a318d2450be471c44cbe98dc74bca74cb8313da..f52dad937d3287caf9ed626557e2cddc7280222c 100644 (file)
@@ -549,8 +549,9 @@ void init(int argc, char **argv)
                        exit(1);
        }
 
-       if (check_config_validity() < 0) {
-               Alert("Errors found in configuration.\n");
+       err_code |= check_config_validity();
+       if (err_code & (ERR_ABORT|ERR_FATAL)) {
+               Alert("Fatal errors found in configuration.\n");
                exit(1);
        }