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.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 52d6022..8f612ee 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -1465,6 +1465,23 @@
}
/*
+ * 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.
* Returns the error code, 0 if OK, or any combination of :
* - ERR_ABORT: must abort ASAP
@@ -1491,6 +1508,7 @@
int missing_lf = -1;
int nested_cond_lvl = 0;
enum nested_cond_state nested_conds[MAXNESTEDCONDS];
+ int non_global_section_parsed = 0;
if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
ha_alert("parsing [%s] : out of memory.\n", file);
@@ -1827,6 +1845,12 @@
cursection = ics->section_name;
pcs = cs;
cs = ics;
+
+ if (global.mode & MODE_DIAG) {
+ check_section_position(args[0], file, linenum,
+ &non_global_section_parsed);
+ }
+
break;
}
}