MINOR: config: Export parse_process_number and use it wherever it's applicable

This function is used when "bind-process" directive is parsed and when "process"
parameter on a "bind" or a "stats socket" line is parsed.
This commit is contained in:
Christopher Faulet 2017-11-22 12:06:43 +01:00 committed by Willy Tarreau
parent 5ab51775e7
commit f1f0c5f591
4 changed files with 9 additions and 99 deletions

View File

@ -86,6 +86,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, char **err);
/*
* Sends a warning if proxy <proxy> does not have at least one of the

View File

@ -596,7 +596,7 @@ static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where
* Note: this function can also be used to parse a thread number or a set of
* threads.
*/
static int parse_process_number(const char *arg, unsigned long *proc, char **err)
int parse_process_number(const char *arg, unsigned long *proc, char **err)
{
if (strcmp(arg, "all") == 0)
*proc |= ~0UL;
@ -3283,43 +3283,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
unsigned long set = 0;
while (*args[cur_arg]) {
unsigned int low, high;
if (strcmp(args[cur_arg], "all") == 0) {
set = 0;
break;
}
else if (strcmp(args[cur_arg], "odd") == 0) {
set |= ~0UL/3UL; /* 0x555....555 */
}
else if (strcmp(args[cur_arg], "even") == 0) {
set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
}
else if (isdigit((int)*args[cur_arg])) {
char *dash = strchr(args[cur_arg], '-');
low = high = str2uic(args[cur_arg]);
if (dash)
high = str2uic(dash + 1);
if (high < low) {
unsigned int swap = low;
low = high;
high = swap;
}
if (low < 1 || high > LONGBITS) {
Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n",
file, linenum, args[0], LONGBITS);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
while (low <= high)
set |= 1UL << (low++ - 1);
}
else {
Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n",
file, linenum, args[0], LONGBITS);
if (parse_process_number(args[cur_arg], &set, &errmsg)) {
Alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}

View File

@ -323,43 +323,12 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
}
while (*args[cur_arg]) {
unsigned int low, high;
if (strcmp(args[cur_arg], "all") == 0) {
set = 0;
break;
}
else if (strcmp(args[cur_arg], "odd") == 0) {
set |= ~0UL/3UL; /* 0x555....555 */
}
else if (strcmp(args[cur_arg], "even") == 0) {
set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
}
else if (isdigit((int)*args[cur_arg])) {
char *dash = strchr(args[cur_arg], '-');
low = high = str2uic(args[cur_arg]);
if (dash)
high = str2uic(dash + 1);
if (high < low) {
unsigned int swap = low;
low = high;
high = swap;
}
if (low < 1 || high > LONGBITS) {
memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n",
args[0], args[1], LONGBITS);
return -1;
}
while (low <= high)
set |= 1UL << (low++ - 1);
}
else {
memprintf(err,
"'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n",
args[0], args[1], LONGBITS);
if (parse_process_number(args[cur_arg], &set, err)) {
memprintf(err, "'%s %s' : %s", args[0], args[1], *err);
return -1;
}
cur_arg++;

View File

@ -19,6 +19,7 @@
#include <fcntl.h>
#include <common/accept4.h>
#include <common/cfgparse.h>
#include <common/config.h>
#include <common/errors.h>
#include <common/mini-clist.h>
@ -941,39 +942,9 @@ static int bind_parse_nice(char **args, int cur_arg, struct proxy *px, struct bi
static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
{
unsigned long set = 0;
unsigned int low, high;
if (strcmp(args[cur_arg + 1], "all") == 0) {
set |= ~0UL;
}
else if (strcmp(args[cur_arg + 1], "odd") == 0) {
set |= ~0UL/3UL; /* 0x555....555 */
}
else if (strcmp(args[cur_arg + 1], "even") == 0) {
set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
}
else if (isdigit((int)*args[cur_arg + 1])) {
char *dash = strchr(args[cur_arg + 1], '-');
low = high = str2uic(args[cur_arg + 1]);
if (dash)
high = str2uic(dash + 1);
if (high < low) {
unsigned int swap = low;
low = high;
high = swap;
}
if (low < 1 || high > LONGBITS) {
memprintf(err, "'%s' : invalid range %d-%d, allowed range is 1..%d", args[cur_arg], low, high, LONGBITS);
return ERR_ALERT | ERR_FATAL;
}
while (low <= high)
set |= 1UL << (low++ - 1);
}
else {
memprintf(err, "'%s' expects 'all', 'odd', 'even', or a process range with numbers from 1 to %d.", args[cur_arg], LONGBITS);
if (parse_process_number(args[cur_arg + 1], &set, err)) {
memprintf(err, "'%s' : %s", args[cur_arg], *err);
return ERR_ALERT | ERR_FATAL;
}