From: Willy Tarreau Date: Wed, 7 Oct 2026 14:06:44 +0000 (+0200) Subject: MINOR: cfgparse: expose the keyword modifier to the keyword parsers X-Git-Tag: v3.5-dev9~155 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=673276c9e6cfcb3372a05dc53139fdca43a9cee3;p=haproxy.git MINOR: cfgparse: expose the keyword modifier to the keyword parsers 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". --- diff --git a/include/haproxy/cfgparse.h b/include/haproxy/cfgparse.h index 161b7d31d..926b583be 100644 --- a/include/haproxy/cfgparse.h +++ b/include/haproxy/cfgparse.h @@ -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; diff --git a/src/cfgparse.c b/src/cfgparse.c index b5cae5af5..ec181cd56 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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) {