MINOR: cfgparse: make the process/thread parser support a maximum value

It was hard-wired to LONGBITS, let's make it configurable depending on the
context (threads, processes).
This commit is contained in:
Willy Tarreau 2019-01-26 13:25:14 +01:00
parent 4707033932
commit c9a82e48bf
6 changed files with 13 additions and 12 deletions

View File

@ -115,7 +115,7 @@ int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_c
int too_many_args(int maxarg, char **args, char **msg, int *err_code);
int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code);
int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code);
int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err);
int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err);
unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err);
void free_email_alert(struct proxy *p);

View File

@ -949,14 +949,14 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
if ((slash = strchr(args[1], '/')) != NULL)
*slash = 0;
if (parse_process_number(args[1], &proc, &autoinc, &errmsg)) {
if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
if (slash) {
if (parse_process_number(slash+1, &thread, NULL, &errmsg)) {
if (parse_process_number(slash+1, &thread, MAX_THREADS, NULL, &errmsg)) {
ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;

View File

@ -922,7 +922,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
set = 0;
break;
}
if (parse_process_number(args[cur_arg], &set, NULL, &errmsg)) {
if (parse_process_number(args[cur_arg], &set, LONGBITS, NULL, &errmsg)) {
ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;

View File

@ -345,14 +345,14 @@ int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const
}
/* Parse a string representing a process number or a set of processes. It must
* be "all", "odd", "even", a number between 1 and <LONGBITS> or a range with
* be "all", "odd", "even", a number between 1 and <max> or a range with
* two such numbers delimited by a dash ('-'). On success, it returns
* 0. otherwise it returns 1 with an error message in <err>.
*
* Note: this function can also be used to parse a thread number or a set of
* threads.
*/
int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err)
int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err)
{
if (autoinc) {
*autoinc = 0;
@ -379,7 +379,7 @@ int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, cha
low = high = str2uic(arg);
if ((dash = strchr(arg, '-')) != NULL)
high = ((!*(dash+1)) ? LONGBITS : str2uic(dash + 1));
high = ((!*(dash+1)) ? max : str2uic(dash + 1));
if (high < low) {
unsigned int swap = low;
@ -387,16 +387,17 @@ int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, cha
high = swap;
}
if (low < 1 || low > LONGBITS || high > LONGBITS) {
if (low < 1 || low > max || high > max) {
memprintf(err, "'%s' is not a valid number/range."
" It supports numbers from 1 to %d.\n",
arg, LONGBITS);
arg, max);
return 1;
}
for (;low <= high; low++)
*proc |= 1UL << (low-1);
}
*proc &= ~0UL >> (LONGBITS - max);
return 0;
}

View File

@ -359,7 +359,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
set = 0;
break;
}
if (parse_process_number(args[cur_arg], &set, NULL, err)) {
if (parse_process_number(args[cur_arg], &set, LONGBITS, NULL, err)) {
memprintf(err, "'%s %s' : %s", args[0], args[1], *err);
return -1;
}

View File

@ -961,13 +961,13 @@ static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct
if ((slash = strchr(args[cur_arg + 1], '/')) != NULL)
*slash = 0;
if (parse_process_number(args[cur_arg + 1], &proc, NULL, err)) {
if (parse_process_number(args[cur_arg + 1], &proc, LONGBITS, NULL, err)) {
memprintf(err, "'%s' : %s", args[cur_arg], *err);
return ERR_ALERT | ERR_FATAL;
}
if (slash) {
if (parse_process_number(slash+1, &thread, NULL, err)) {
if (parse_process_number(slash+1, &thread, MAX_THREADS, NULL, err)) {
memprintf(err, "'%s' : %s", args[cur_arg], *err);
return ERR_ALERT | ERR_FATAL;
}