MINOR: cfgparse: parse tune.bufsize.small as a size

Till now this value was parsed as raw integer using atol() and would
silently ignore any trailing suffix, causing unexpected behaviors when
set, e.g. to "4k". Let's make use of parse_size_err() on it so that
units are supported. This requires to turn it to uint as well, which
was verified to be OK.
This commit is contained in:
Willy Tarreau 2024-11-18 19:07:05 +01:00
parent a344d37fad
commit e72b525832
3 changed files with 10 additions and 4 deletions

View File

@ -3336,7 +3336,7 @@ tune.bufsize <size>
value set using this parameter will automatically be rounded up to the next
multiple of 8 on 32-bit machines and 16 on 64-bit machines.
tune.bufsize.small <number>
tune.bufsize.small <size>
Sets the size in bytes for small buffers. The defaults value is 1024.
These buffers are designed to be used in some specific contexts where memory

View File

@ -166,7 +166,7 @@ struct global {
int runqueue_depth;/* max number of tasks to run at once */
uint recv_enough; /* how many input bytes at once are "enough" */
uint bufsize; /* buffer size in bytes, defaults to BUFSIZE */
int bufsize_small; /* small buffer size in bytes */
uint bufsize_small;/* small buffer size in bytes */
int maxrewrite; /* buffer max rewrite size in bytes, defaults to MAXREWRITE */
int reserved_bufs; /* how many buffers can only be allocated for response */
int buf_limit; /* if not null, how many total buffers may only be allocated */

View File

@ -193,7 +193,8 @@ static int cfg_parse_tune_bufsize_small(char **args, int section_type,
struct proxy *curpx, const struct proxy *defpx,
const char *file, int line, char **err)
{
int size;
const char *res;
uint size;
if (too_many_args(1, args, err, NULL))
goto err;
@ -203,7 +204,12 @@ static int cfg_parse_tune_bufsize_small(char **args, int section_type,
goto err;
}
size = atol(args[1]);
res = parse_size_err(args[1], &size);
if (res != NULL) {
memprintf(err, "unexpected '%s' after size passed to '%s'", res, args[0]);
goto err;
}
if (size <= 0) {
memprintf(err, "'%s' expects a positive integer argument.\n", args[0]);
goto err;