]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: make the process/thread parser support a maximum value
authorWilly Tarreau <w@1wt.eu>
Sat, 26 Jan 2019 12:25:14 +0000 (13:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 26 Jan 2019 12:25:14 +0000 (13:25 +0100)
It was hard-wired to LONGBITS, let's make it configurable depending on the
context (threads, processes).

include/common/cfgparse.h
src/cfgparse-global.c
src/cfgparse-listen.c
src/cfgparse.c
src/cli.c
src/listener.c

index b46e02b99c30ae650a78ec4e9fd8eac85ec4c368..1a288166aa2525975aef292b2aa4770f4d5c6a6b 100644 (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);
 
index 5a92d9b313fc57ca7bc7ffee7fc3e9819363934c..2cdcf76616db3a9a643612b09a657dfae3e7cb97 100644 (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;
index 2a7ed5337455cd5549eb7055ab9557929b974c52..74218b5e65cbdb1d185546d2fe888bac36135906 100644 (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;
index 05b6d9e581121b8d90ddd3814722ef9e58835423..50f43cde59a3ed880d8317d5e90dc6d6c9ad3cdb 100644 (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;
 }
index 687796fa5e890acaa9bd3dc84fe58626c6b825f3..d1d1e9625d08ecece35bda6fa92f3f2d2ff919c4 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -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;
                        }
index 2c885e998cf5127d12d27bf2268e7554464a3b79..9a79e6aba3848c53e85098888ed8a0b6502e5ec0 100644 (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;
                }