From: William Lallemand Date: Fri, 11 Oct 2024 15:38:46 +0000 (+0200) Subject: MINOR: cfgparse: simulate long configuration parsing with force-cfg-parser-pause X-Git-Tag: v3.1-dev10~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=edf85a1d76a772b70e81919ec4e919e06477fd39;p=thirdparty%2Fhaproxy.git MINOR: cfgparse: simulate long configuration parsing with force-cfg-parser-pause This command is pausing the configuration parser for milliseconds. This is useful for development or for testing timeouts of init scripts, particularly to simulate a very long reload. It requires the expose-experimental-directives to be set. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index a1460be70e..1c5cc93375 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -4304,6 +4304,23 @@ anonkey from the CLI command "set anon global-key". See also command line argument "-dC" in the management manual. +force-cfg-parser-pause + This command is pausing the configuration parser for milliseconds. + This is useful for development or for testing timeouts of init scripts, + particularly to simulate a very long reload. + It requires the expose-experimental-directives to be set. + + is the timeout value specified in milliseconds by default, but + can be in any other unit if the number is suffixed by the unit, + as explained at the top of this document. + + Example: + + global + expose-experimental-directives + force-cfg-parser-pause 10s + + quick-exit This speeds up the old process exit upon reload by skipping the releasing of memory objects and listeners, since all of these are reclaimed by the diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index 12cac06e3c..5be150f5fa 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -1474,8 +1474,51 @@ static int cfg_parse_global_env_opts(char **args, int section_type, return 0; } +static int cfg_parse_global_parser_pause(char **args, int section_type, + struct proxy *curpx, const struct proxy *defpx, + const char *file, int line, char **err) +{ + unsigned int ms = 0; + const char *res; + + if (*(args[1]) == 0) { + memprintf(err, "'%s' expects a timer value between 0 and 65535 ms.", args[0]); + return -1; + } + + if (too_many_args(1, args, err, NULL)) + return -1; + + + res = parse_time_err(args[1], &ms, TIME_UNIT_MS); + if (res == PARSE_TIME_OVER) { + memprintf(err, "timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.", + args[1], args[0]); + return -1; + } + else if (res == PARSE_TIME_UNDER) { + memprintf(err, "timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.", + args[1], args[0]); + return -1; + } + else if (res) { + memprintf(err, "unexpected character '%c' in argument to <%s>.", *res, args[0]); + return -1; + } + + if (ms > 65535) { + memprintf(err, "'%s' expects a timer value between 0 and 65535 ms.", args[0]); + return -1; + } + + usleep(ms * 1000); + + return 0; +} + static struct cfg_kw_list cfg_kws = {ILH, { { CFG_GLOBAL, "prealloc-fd", cfg_parse_prealloc_fd }, + { CFG_GLOBAL, "force-cfg-parser-pause", cfg_parse_global_parser_pause, KWF_EXPERIMENTAL }, { CFG_GLOBAL, "harden.reject-privileged-ports.tcp", cfg_parse_reject_privileged_ports }, { CFG_GLOBAL, "harden.reject-privileged-ports.quic", cfg_parse_reject_privileged_ports }, { CFG_GLOBAL, "master-worker", cfg_parse_global_master_worker },