mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MINOR: config: use a standard parser for the "nbthread" keyword
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.
This commit is contained in:
parent
614e68337d
commit
51ec03a61d
@ -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;
|
||||
|
44
src/thread.c
44
src/thread.c
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user