]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: use a standard parser for the "nbthread" keyword
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Sep 2021 09:55:22 +0000 (11:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 27 Sep 2021 07:47:40 +0000 (09:47 +0200)
Probably because of some copy-paste from "nbproc", "nbthread" used to
be parsed in cfgparse instead of using a registered parser. Let's fix
this to clean up the code base now.

src/cfgparse-global.c
src/thread.c

index 4dc93b68a3d0d33417661c5f610296358aa82aba..a9e1b94808fd30af0dbb17bd333075a70fccab73 100644 (file)
@@ -38,7 +38,7 @@ static const char *common_kw_list[] = {
        "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize",
        "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr",
        "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid",
-       "external-check", "user", "group", "nbproc", "nbthread", "maxconn",
+       "external-check", "user", "group", "nbproc", "maxconn",
        "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate",
        "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n",
        "chroot", "description", "node", "pidfile", "unix-bind", "log",
@@ -576,27 +576,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                err_code |= ERR_ALERT | ERR_FATAL;
                goto out;
        }
-       else if (strcmp(args[0], "nbthread") == 0) {
-               if (alertif_too_many_args(1, file, linenum, args, &err_code))
-                       goto out;
-               if (*(args[1]) == 0) {
-                       ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
-               HA_DIAG_WARNING_COND(global.nbthread,
-                                    "parsing [%s:%d] : nbthread is already defined and will be overridden.\n",
-                                    file, linenum);
-
-               global.nbthread = parse_nbthread(args[1], &errmsg);
-               if (!global.nbthread) {
-                       ha_alert("parsing [%s:%d] : '%s' %s.\n",
-                                file, linenum, args[0], errmsg);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-       }
        else if (strcmp(args[0], "maxconn") == 0) {
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
index 44375e62f3a041d72db414f1f6b1409a669db125..5cc1b29751154178c1d413a6c154a4510985eb17 100644 (file)
@@ -301,33 +301,51 @@ REGISTER_BUILD_OPTS("Built without multi-threading support (USE_THREAD not set).
 #endif // USE_THREAD
 
 
-/* Parse the number of threads in argument <arg>, returns it and adjusts a few
- * internal variables accordingly, or fails and returns zero with an error
- * reason in <errmsg>. May be called multiple times while parsing.
+/* Parse the "nbthread" global directive, which takes an integer argument that
+ * contains the desired number of threads.
  */
-int parse_nbthread(const char *arg, char **err)
+static int cfg_parse_nbthread(char **args, int section_type, struct proxy *curpx,
+                              const struct proxy *defpx, const char *file, int line,
+                              char **err)
 {
        long nbthread;
        char *errptr;
 
-       nbthread = strtol(arg, &errptr, 10);
-       if (!*arg || *errptr) {
-               memprintf(err, "passed a missing or unparsable integer value in '%s'", arg);
-               return 0;
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+       nbthread = strtol(args[1], &errptr, 10);
+       if (!*args[1] || *errptr) {
+               memprintf(err, "'%s' passed a missing or unparsable integer value in '%s'", args[0], args[1]);
+               return -1;
        }
 
 #ifndef USE_THREAD
        if (nbthread != 1) {
-               memprintf(err, "specified with a value other than 1 while HAProxy is not compiled with threads support. Please check build options for USE_THREAD");
-               return 0;
+               memprintf(err, "'%s' specified with a value other than 1 while HAProxy is not compiled with threads support. Please check build options for USE_THREAD", args[0]);
+               return -1;
        }
 #else
        if (nbthread < 1 || nbthread > MAX_THREADS) {
-               memprintf(err, "value must be between 1 and %d (was %ld)", MAX_THREADS, nbthread);
-               return 0;
+               memprintf(err, "'%s' value must be between 1 and %d (was %ld)", args[0], MAX_THREADS, nbthread);
+               return -1;
        }
 
        all_threads_mask = nbits(nbthread);
 #endif
-       return nbthread;
+
+       HA_DIAG_WARNING_COND(global.nbthread,
+                            "parsing [%s:%d] : nbthread is already defined and will be overridden.\n",
+                            file, line);
+
+       global.nbthread = nbthread;
+       return 0;
 }
+
+/* config keyword parsers */
+static struct cfg_kw_list cfg_kws = {ILH, {
+       { CFG_GLOBAL, "nbthread",       cfg_parse_nbthread, 0 },
+       { 0, NULL, NULL }
+}};
+
+INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);