]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse-global: move mode's keywords in cfg_kw_list
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Tue, 16 Jul 2024 16:02:53 +0000 (18:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 18 Jul 2024 12:15:52 +0000 (14:15 +0200)
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;

src/cfgparse-global.c

index 452c0e54536bb8894b77dd9bc0a2d19282197925..b2926fda257fe8ce4fcd47b41fb0eceb390aadb2 100644 (file)
@@ -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 },
 }};