[MINOR] report correct section type for unknown keywords.

An unknown keyword was always reported in section "listen" for any
section type (defaults, listen, frontend, backend, ...).
(cherry picked from commit 6daf34352f)
This commit is contained in:
Willy Tarreau 2008-01-22 16:44:08 +01:00
parent 89cacf7007
commit 8c1e6c98f3
2 changed files with 60 additions and 13 deletions

View file

@ -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

View 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;
}