]> git.kaiwu.me - haproxy.git/commitdiff
[MINOR] report correct section type for unknown keywords.
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Jan 2008 15:44:08 +0000 (16:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 8 Mar 2008 20:47:10 +0000 (21:47 +0100)
An unknown keyword was always reported in section "listen" for any
section type (defaults, listen, frontend, backend, ...).
(cherry picked from commit 6daf34352f325699efa8f731e5525275523786b9)

examples/test-section-kw.cfg [new file with mode: 0644]
src/cfgparse.c

diff --git a/examples/test-section-kw.cfg b/examples/test-section-kw.cfg
new file mode 100644 (file)
index 0000000..f1bece7
--- /dev/null
@@ -0,0 +1,26 @@
+# This is a test configuration. It must produce errors with the correct
+# section types.
+
+# out of section keyword
+#keyword_out
+
+global
+       # unknown keyword in section 'global'
+       #keyword_glob
+
+defaults
+       # unknown keyword in section 'global'
+       #keyword_def
+
+listen  listen1
+       # unknown keyword in section 'listen'
+       #keyword_lis
+
+frontend front1
+       # unknown keyword in section 'frontend'
+       #keyword_frt
+
+backend back1
+       # unknown keyword in section 'backend'
+       #keyword_bck
+
index 70a371b175801612ea373505b2ba083340f09604..2fd5007cdf18095feccc6e5c5ad8316f3c897742 100644 (file)
@@ -116,6 +116,7 @@ static const struct {
 };
 
 
+static char *cursection = NULL;
 static struct proxy defproxy;          /* fake proxy used to assign default values on all instances */
 int cfg_maxpconn = DEFAULT_MAXCONN;    /* # of simultaneous connections per proxy (-N) */
 int cfg_maxconn = 0;           /* # of simultaneous connections, (-n) */
@@ -2418,7 +2419,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                }
        }
        else {
-               Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "listen");
+               Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
                return -1;
        }
        return 0;
@@ -2461,7 +2462,7 @@ int readcfgfile(const char *file)
                         */
                        Alert("parsing [%s:%d]: line too long, limit: %d.\n",
                                file, linenum, sizeof(thisline)-1);
-                       return -1;
+                       goto err;
                }
 
                /* skip leading spaces */
@@ -2505,7 +2506,7 @@ int readcfgfile(const char *file)
                                        }
                                        else {
                                                Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
-                                               return -1;
+                                               goto err;
                                        }
                                }
                                if (skip) {
@@ -2550,33 +2551,44 @@ int readcfgfile(const char *file)
 
                if (inv && strcmp(args[0], "option")) {
                        Alert("parsing [%s:%d]: negation currently supported only for options.\n", file, linenum);
-                       return -1;
+                       goto err;
                }
 
                if (!strcmp(args[0], "listen") ||
                    !strcmp(args[0], "frontend") ||
                    !strcmp(args[0], "backend") ||
                    !strcmp(args[0], "ruleset") ||
-                   !strcmp(args[0], "defaults"))  /* new proxy */
+                   !strcmp(args[0], "defaults")) { /* new proxy */
                        confsect = CFG_LISTEN;
-               else if (!strcmp(args[0], "global"))  /* global config */
+                       if (cursection)
+                               free(cursection);
+                       cursection = strdup(args[0]);
+               }
+               else if (!strcmp(args[0], "global")) { /* global config */
                        confsect = CFG_GLOBAL;
+                       if (cursection)
+                               free(cursection);
+                       cursection = strdup(args[0]);
+               }
                /* else it's a section keyword */
 
                switch (confsect) {
                case CFG_LISTEN:
                        if (cfg_parse_listen(file, linenum, args, inv) < 0)
-                               return -1;
+                               goto err;
                        break;
                case CFG_GLOBAL:
                        if (cfg_parse_global(file, linenum, args, inv) < 0)
-                               return -1;
+                               goto err;
                        break;
                default:
                        Alert("parsing [%s:%d] : unknown keyword '%s' out of section.\n", file, linenum, args[0]);
-                       return -1;
+                       goto err;
                }
        }
+       if (cursection)
+               free(cursection);
+       cursection = NULL;
        fclose(f);
 
        /*
@@ -2589,7 +2601,7 @@ int readcfgfile(const char *file)
        if ((curproxy = proxy) == NULL) {
                Alert("parsing %s : no <listen> line. Nothing to do !\n",
                      file);
-               return -1;
+               goto err;
        }
 
        while (curproxy != NULL) {
@@ -2859,7 +2871,7 @@ int readcfgfile(const char *file)
                        } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) {
                                Alert("parsing %s, %s '%s' : fullconn is mandatory when minconn is set on a server.\n",
                                      file, proxy_type_str(curproxy), curproxy->id, linenum);
-                               return -1;
+                               goto err;
                        }
 
                        if (newsrv->maxconn > 0) {
@@ -2867,7 +2879,7 @@ int readcfgfile(const char *file)
 
                                if ((t = pool_alloc2(pool2_task)) == NULL) {
                                        Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                                       return -1;
+                                       goto err;
                                }
                
                                t->qlist.p = NULL;
@@ -2903,7 +2915,7 @@ int readcfgfile(const char *file)
 
        if (cfgerr > 0) {
                Alert("Errors found in configuration file, aborting.\n");
-               return -1;
+               goto err;
        }
 
        /*
@@ -2921,7 +2933,16 @@ int readcfgfile(const char *file)
                }
        }
 
+       if (cursection)
+               free(cursection);
+       cursection = NULL;
        return 0;
+
+ err:
+       if (cursection)
+               free(cursection);
+       cursection = NULL;
+       return -1;
 }