From: Valentine Krasnobaeva Date: Tue, 16 Jul 2024 16:02:53 +0000 (+0200) Subject: MINOR: cfgparse-global: move mode's keywords in cfg_kw_list X-Git-Tag: v3.1-dev4~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=118ac11ce;p=thirdparty%2Fhaproxy.git MINOR: cfgparse-global: move mode's keywords in cfg_kw_list This commit cleans up cfg_parse_global() and prepares the config parser for master-worker mode refactoring, where daemon and master-worker fork() calls will happen very early in init(). So, the config in such case should be read twice: - at first: only some keywords in the global section for the mode discovery and everything, which is related to master process by opportunity; - at second: except the master process, all other keywords would be parsed; --- diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index 452c0e5453..b2926fda25 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -81,25 +81,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) else if (strcmp(args[0], "expose-experimental-directives") == 0) { experimental_directives_allowed = 1; } - else if (strcmp(args[0], "daemon") == 0) { - if (alertif_too_many_args(0, file, linenum, args, &err_code)) - goto out; - global.mode |= MODE_DAEMON; - } - else if (strcmp(args[0], "master-worker") == 0) { - if (alertif_too_many_args(1, file, linenum, args, &err_code)) - goto out; - if (*args[1]) { - if (strcmp(args[1], "no-exit-on-failure") == 0) { - global.tune.options |= GTUNE_NOEXIT_ONFAILURE; - } else { - ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - } - global.mode |= MODE_MWORKER; - } else if (strcmp(args[0], "noepoll") == 0) { if (alertif_too_many_args(0, file, linenum, args, &err_code)) goto out; @@ -187,16 +168,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) goto out; protocol_clrf_all(PROTO_F_REUSEPORT_SUPPORTED); } - else if (strcmp(args[0], "quiet") == 0) { - if (alertif_too_many_args(0, file, linenum, args, &err_code)) - goto out; - global.mode |= MODE_QUIET; - } - else if (strcmp(args[0], "zero-warning") == 0) { - if (alertif_too_many_args(0, file, linenum, args, &err_code)) - goto out; - global.mode |= MODE_ZERO_WARNING; - } else if (strcmp(args[0], "tune.runqueue-depth") == 0) { if (alertif_too_many_args(1, file, linenum, args, &err_code)) goto out; @@ -1425,10 +1396,61 @@ static int cfg_parse_reject_privileged_ports(char **args, int section_type, return 0; } +/* Parser for master-worker mode */ +static int cfg_parse_global_master_worker(char **args, int section_type, + struct proxy *curpx, const struct proxy *defpx, + const char *file, int line, char **err) +{ + if (too_many_args(1, args, err, NULL)) + return -1; + + if (*args[1]) { + if (strcmp(args[1], "no-exit-on-failure") == 0) + global.tune.options |= GTUNE_NOEXIT_ONFAILURE; + else { + memprintf(err, "parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option", + file, line, args[0]); + return -1; + } + } + global.mode |= MODE_MWORKER; + + return 0; +} + +/* Parser for other modes */ +static int cfg_parse_global_mode(char **args, int section_type, + struct proxy *curpx, const struct proxy *defpx, + const char *file, int line, char **err) +{ + if (too_many_args(0, args, err, NULL)) + return -1; + + if (strcmp(args[0], "daemon") == 0) { + global.mode |= MODE_DAEMON; + + } else if (strcmp(args[0], "quiet") == 0) { + global.mode |= MODE_QUIET; + + } else if (strcmp(args[0], "zero-warning") == 0) { + global.mode |= MODE_ZERO_WARNING; + + } else { + BUG_ON(1, "Triggered in cfg_parse_global_mode() by unsupported keyword.\n"); + return -1; + } + + return 0; +} + static struct cfg_kw_list cfg_kws = {ILH, { { CFG_GLOBAL, "prealloc-fd", cfg_parse_prealloc_fd }, { 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 }, + { CFG_GLOBAL, "daemon", cfg_parse_global_mode } , + { CFG_GLOBAL, "quiet", cfg_parse_global_mode }, + { CFG_GLOBAL, "zero-warning", cfg_parse_global_mode }, { 0, NULL, NULL }, }};