mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-01 02:52:00 +00:00
MINOR: cfgparse: Always check the section position
In diag mode, the section position is checked and a warning is emitted if a global section is defined after any non-global one. Now, this check is always performed. But the warning is still only emitted in diag mode. In addition, the result of this check is now stored in a global variable, to be used from anywhere. The aim of this patch is to be able to restrict usage of some global directives to the very first global sections. It will be useful to avoid undefined behaviors. Indeed, some config parts may depend on global settings and it is a problem if these settings are changed after.
This commit is contained in:
parent
0909f62266
commit
037e3f8735
@ -94,6 +94,7 @@ extern int cfg_maxconn;
|
||||
extern char *cfg_scope;
|
||||
extern struct cfg_kw_list cfg_keywords;
|
||||
extern char *cursection;
|
||||
extern int non_global_section_parsed;
|
||||
|
||||
int cfg_parse_global(const char *file, int linenum, char **args, int inv);
|
||||
int cfg_parse_listen(const char *file, int linenum, char **args, int inv);
|
||||
|
@ -104,6 +104,7 @@ char *cursection = NULL;
|
||||
int cfg_maxpconn = 0; /* # of simultaneous connections per proxy (-N) */
|
||||
int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
|
||||
char *cfg_scope = NULL; /* the current scope during the configuration parsing */
|
||||
int non_global_section_parsed = 0;
|
||||
|
||||
/* how to handle default paths */
|
||||
static enum default_path_mode {
|
||||
@ -1577,16 +1578,14 @@ cfg_parse_track_sc_num(unsigned int *track_sc_num,
|
||||
* Detect a global section after a non-global one and output a diagnostic
|
||||
* warning.
|
||||
*/
|
||||
static void check_section_position(char *section_name,
|
||||
const char *file, int linenum,
|
||||
int *non_global_parsed)
|
||||
static void check_section_position(char *section_name, const char *file, int linenum)
|
||||
{
|
||||
if (strcmp(section_name, "global") == 0) {
|
||||
if (*non_global_parsed == 1)
|
||||
if ((global.mode & MODE_DIAG) && non_global_section_parsed == 1)
|
||||
_ha_diag_warning("parsing [%s:%d] : global section detected after a non-global one, the prevalence of their statements is unspecified\n", file, linenum);
|
||||
}
|
||||
else if (*non_global_parsed == 0) {
|
||||
*non_global_parsed = 1;
|
||||
else if (non_global_section_parsed == 0) {
|
||||
non_global_section_parsed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1743,7 +1742,6 @@ int readcfgfile(const char *file)
|
||||
int missing_lf = -1;
|
||||
int nested_cond_lvl = 0;
|
||||
enum nested_cond_state nested_conds[MAXNESTEDCONDS];
|
||||
int non_global_section_parsed = 0;
|
||||
char *errmsg = NULL;
|
||||
|
||||
global.cfg_curr_line = 0;
|
||||
@ -2455,12 +2453,7 @@ next_line:
|
||||
cs = ics;
|
||||
free(global.cfg_curr_section);
|
||||
global.cfg_curr_section = strdup(*args[1] ? args[1] : args[0]);
|
||||
|
||||
if (global.mode & MODE_DIAG) {
|
||||
check_section_position(args[0], file, linenum,
|
||||
&non_global_section_parsed);
|
||||
}
|
||||
|
||||
check_section_position(args[0], file, linenum);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user