]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: improve config check return codes
authorWilly Tarreau <w@1wt.eu>
Thu, 2 Feb 2012 16:48:18 +0000 (17:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 2 Feb 2012 16:53:37 +0000 (17:53 +0100)
When checking a configuration file using "-c -f xxx", sometimes it is
reported that a config is valid while it will later fail (eg: no enabled
listener). Instead, let's improve the return values :
  - return 0 if config is 100% OK
  - return 1 if config has errors
  - return 2 if config is OK but no listener nor peer is enabled

src/cfgparse.c
src/haproxy.c

index 6fa549a37df88770db3e160c55af4eabeac3f507..73b7f7135c1bed5777ad737b63318a929bb0275d 100644 (file)
@@ -5574,12 +5574,6 @@ int check_config_validity()
                proxy = next;
        }
 
-       if ((curproxy = proxy) == NULL) {
-               Alert("config : no <listen> line. Nothing to do !\n");
-               err_code |= ERR_ALERT | ERR_FATAL;
-               goto out;
-       }
-
        while (curproxy != NULL) {
                struct switching_rule *rule;
                struct sticking_rule *mrule;
index 363f30617ca18dc5b2356b61bac801893b266a19..66cf18f594c9804a31bcd8b81f4270d364ddaf9a 100644 (file)
@@ -548,8 +548,24 @@ void init(int argc, char **argv)
        }
 
        if (global.mode & MODE_CHECK) {
-               qfprintf(stdout, "Configuration file is valid\n");
-               exit(0);
+               struct peers *pr;
+               struct proxy *px;
+
+               for (pr = peers; pr; pr = pr->next)
+                       if (pr->peers_fe)
+                               break;
+
+               for (px = proxy; px; px = px->next)
+                       if (px->state == PR_STNEW && px->listen)
+                               break;
+
+               if (pr || px) {
+                       /* At least one peer or one listener has been found */
+                       qfprintf(stdout, "Configuration file is valid\n");
+                       exit(0);
+               }
+               qfprintf(stdout, "Configuration file has no error but will not start (no listener) => exit(2).\n");
+               exit(2);
        }
 
        global_listener_queue_task = task_new();