]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: cfgparse: expose the keyword modifier to the keyword parsers
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Oct 2026 14:06:44 +0000 (16:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2026 07:31:07 +0000 (09:31 +0200)
Section parsers receive the keyword modifier ("no" or "default") found in
front of the keyword as their last argument, but the keyword parsers which
are registered in a cfg_kw_list only receive the arguments, the file name
and the line number. As a consequence, a keyword supporting negation such
as "busy-polling" cannot be moved out of a section parser.

Let's just expose the modifier of the line being parsed in a new global
variable, cfg_curr_kwm, which is set for each new line in readcfgfile()
and reset once the file is completely parsed. This way the few keyword
parsers which are interested in it may consult it, the same way they
already consult "file" and "line".

include/haproxy/cfgparse.h
src/cfgparse.c

index 161b7d31d6a0a47f9fb5f3c3681fd29380c12769..926b583be697ec6606a59ca4239f1f5c98e6f916 100644 (file)
@@ -109,6 +109,7 @@ extern char *cfg_scope;
 extern struct cfg_kw_list cfg_keywords;
 extern char *cursection;
 extern int non_global_section_parsed;
+extern int cfg_curr_kwm;
 
 extern struct proxy *curproxy;
 extern struct proxy *last_defproxy;
index b5cae5af52a16437b41beee786917c7d0596455f..ec181cd56e5613ac2847d039a3b3cb20e4466647 100644 (file)
@@ -119,6 +119,14 @@ 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;
 
+/* keyword modifier ("no" or "default") found in front of the keyword which is
+ * currently being parsed. It is reset for each new line, and is only meaningful
+ * during the config parsing. Section parsers receive it as an argument, but the
+ * keyword parsers registered in a cfg_kw_list don't, so those which support a
+ * modifier have to consult this variable.
+ */
+int cfg_curr_kwm = KWM_STD;
+
 /* how to handle default paths */
 static enum default_path_mode {
        DEFAULT_PATH_CURRENT = 0,  /* "current": paths are relative to CWD (this is the default) */
@@ -2131,6 +2139,9 @@ next_line:
                        lshift_args(args);
                }
 
+               /* also expose it to the keyword parsers, which don't receive it */
+               cfg_curr_kwm = kwm;
+
                if (kwm != KWM_STD && strcmp(args[0], "option") != 0 &&
                    strcmp(args[0], "log") != 0 && strcmp(args[0], "busy-polling") != 0 &&
                    strcmp(args[0], "set-dumpable") != 0 && strcmp(args[0], "strict-limits") != 0 &&
@@ -2216,6 +2227,7 @@ section_parser:
        }
 
        ha_free(&global.cfg_curr_section);
+       cfg_curr_kwm = KWM_STD;
 
        /* call post_section_parser of the last section when there is no more lines */
        if (cs) {