Skip to content

Commit af1d170

Browse files
einval22wlallemand
authored andcommitted
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.
1 parent 8a1aabb commit af1d170

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/mworker.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -802,29 +802,29 @@ static int cli_io_handler_show_loadstatus(struct appctx *appctx)
802802
static int mworker_parse_global_max_reloads(char **args, int section_type, struct proxy *curpx,
803803
const struct proxy *defpx, const char *file, int linenum, char **err)
804804
{
805-
806-
int err_code = 0;
807805
if (!(global.mode & MODE_DISCOVERY))
808806
return 0;
809807

810-
if (alertif_too_many_args(1, file, linenum, args, &err_code))
811-
goto out;
808+
if (strcmp(args[0], "mworker-max-reloads") == 0) {
809+
if (too_many_args(1, args, err, NULL))
810+
return -1;
812811

813-
if (*(args[1]) == 0) {
814-
memprintf(err, "%sparsing [%s:%d] : '%s' expects an integer argument.\n", *err, file, linenum, args[0]);
815-
err_code |= ERR_ALERT | ERR_FATAL;
816-
goto out;
817-
}
812+
if (*(args[1]) == 0) {
813+
memprintf(err, "'%s' expects an integer argument.", args[0]);
814+
return -1;
815+
}
818816

819-
max_reloads = atol(args[1]);
820-
if (max_reloads < 0) {
821-
memprintf(err, "%sparsing [%s:%d] '%s' : invalid value %d, must be >= 0", *err, file, linenum, args[0], max_reloads);
822-
err_code |= ERR_ALERT | ERR_FATAL;
823-
goto out;
817+
max_reloads = atol(args[1]);
818+
if (max_reloads < 0) {
819+
memprintf(err, "'%s' expects a positive value or zero.", args[0]);
820+
return -1;
821+
}
822+
} else {
823+
BUG_ON(1, "Triggered in mworker_parse_global_max_reloads() by unsupported keyword.\n");
824+
return -1;
824825
}
825826

826-
out:
827-
return err_code;
827+
return 0;
828828
}
829829

830830
void mworker_free_child(struct mworker_proc *child)

0 commit comments

Comments
 (0)