From 7e69007d4a10408b922426327e70eaf1f0572a74 Mon Sep 17 00:00:00 2001 From: Valentine Krasnobaeva Date: Sat, 12 Oct 2024 14:02:53 +0200 Subject: [PATCH] BUG/MINOR: mworker: fix mworker-max-reloads parser Before this patch, when wrong argument was provided in the configuration for mworker-max-reloads keyword, parser shows these errors below on the stderr: [WARNING] (1820317) : config : parsing [haproxy.cfg:154] : (null)parsing [haproxy.cfg:154] : 'mworker-max-reloads' expects an integer argument. In a case, when by mistake two arguments were provided instead of one, this has also triggered a buggy error message: [ALERT] (1820668) : config : parsing [haproxy.cfg:154] : 'mworker-max-reloads' cannot handle unexpected argument '45'. [WARNING] (1820668) : config : parsing [haproxy.cfg:154] : (null) So, as 'mworker-max-reloads' is parsed in discovery mode by master process let's align now its parser with all others, which could be called for this mode. Like this in cases, when there are too many args or argument isn't a valid integer we return proper error codes to global section parser and messages are formated properly. This fix should be backported in all stable versions. (cherry picked from commit af1d170122369094a1f3869791fb34fb7286e31e) Signed-off-by: Christopher Faulet --- src/mworker.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/mworker.c b/src/mworker.c index c4461cc..6aefcc5 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -748,27 +748,26 @@ static int cli_io_handler_show_loadstatus(struct appctx *appctx) static int mworker_parse_global_max_reloads(char **args, int section_type, struct proxy *curpx, const struct proxy *defpx, const char *file, int linenum, char **err) { + if (strcmp(args[0], "mworker-max-reloads") == 0) { + if (too_many_args(1, args, err, NULL)) + return -1; - int err_code = 0; - - if (alertif_too_many_args(1, file, linenum, args, &err_code)) - goto out; - - if (*(args[1]) == 0) { - memprintf(err, "%sparsing [%s:%d] : '%s' expects an integer argument.\n", *err, file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } + if (*(args[1]) == 0) { + memprintf(err, "'%s' expects an integer argument.", args[0]); + return -1; + } - max_reloads = atol(args[1]); - if (max_reloads < 0) { - memprintf(err, "%sparsing [%s:%d] '%s' : invalid value %d, must be >= 0", *err, file, linenum, args[0], max_reloads); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; + max_reloads = atol(args[1]); + if (max_reloads < 0) { + memprintf(err, "'%s' expects a positive value or zero.", args[0]); + return -1; + } + } else { + BUG_ON(1, "Triggered in mworker_parse_global_max_reloads() by unsupported keyword.\n"); + return -1; } -out: - return err_code; + return 0; } void mworker_free_child(struct mworker_proc *child) -- 1.7.10.4