MINOR: config: diag if global section after non-global

Detect if a global section is present after another section and reports
a diagnostic about it.
This commit is contained in:
Amaury Denoyelle 2021-03-31 11:43:47 +02:00
parent de2fab55aa
commit 728be0f437
1 changed files with 24 additions and 0 deletions

View File

@ -1464,6 +1464,23 @@ cfg_parse_track_sc_num(unsigned int *track_sc_num,
return 0; return 0;
} }
/*
* 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)
{
if (!strcmp(section_name, "global")) {
if (*non_global_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;
}
}
/* /*
* This function reads and parses the configuration file given in the argument. * This function reads and parses the configuration file given in the argument.
* Returns the error code, 0 if OK, or any combination of : * Returns the error code, 0 if OK, or any combination of :
@ -1491,6 +1508,7 @@ int readcfgfile(const char *file)
int missing_lf = -1; int missing_lf = -1;
int nested_cond_lvl = 0; int nested_cond_lvl = 0;
enum nested_cond_state nested_conds[MAXNESTEDCONDS]; enum nested_cond_state nested_conds[MAXNESTEDCONDS];
int non_global_section_parsed = 0;
if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
ha_alert("parsing [%s] : out of memory.\n", file); ha_alert("parsing [%s] : out of memory.\n", file);
@ -1827,6 +1845,12 @@ int readcfgfile(const char *file)
cursection = ics->section_name; cursection = ics->section_name;
pcs = cs; pcs = cs;
cs = ics; cs = ics;
if (global.mode & MODE_DIAG) {
check_section_position(args[0], file, linenum,
&non_global_section_parsed);
}
break; break;
} }
} }