From: Christopher Faulet Date: Wed, 22 Nov 2017 11:06:43 +0000 (+0100) Subject: MINOR: config: Export parse_process_number and use it wherever it's applicable X-Git-Tag: v1.8.0~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f1f0c5f591334ae00d0eba7898b8b2d6a79594e7;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/common/cfgparse.h b/include/common/cfgparse.h index 230c35fa86..7332bd53a9 100644 --- a/include/common/cfgparse.h +++ b/include/common/cfgparse.h @@ -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 does not have at least one of the diff --git a/src/cfgparse.c b/src/cfgparse.c index 2245f51cf2..d4cfa8641d 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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; } diff --git a/src/cli.c b/src/cli.c index 6625a093d3..05cc15e1d3 100644 --- a/src/cli.c +++ b/src/cli.c @@ -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++; diff --git a/src/listener.c b/src/listener.c index aede0d32df..a06a464f04 100644 --- a/src/listener.c +++ b/src/listener.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -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; }