]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: Export parse_process_number and use it wherever it's applicable
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 22 Nov 2017 11:06:43 +0000 (12:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 24 Nov 2017 14:38:49 +0000 (15:38 +0100)
This function is used when "bind-process" directive is parsed and when "process"
parameter on a "bind" or a "stats socket" line is parsed.

include/common/cfgparse.h
src/cfgparse.c
src/cli.c
src/listener.c

index 230c35fa86cc93adee8bc712706040b46d832b25..7332bd53a9f40a7898eb3742500730b507275099 100644 (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
index 2245f51cf2f2936d0e41294b1f6d5431ef02c53b..d4cfa8641d866925b8565b103ed0550d2813005c 100644 (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;
                        }
index 6625a093d39cff584e8195d1b5eadcdc2e82f6a4..05cc15e1d3e624a64d14c2b1fbfe780169966a97 100644 (file)
--- 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++;
index aede0d32dfbf298a5dbc14659413fa0be811142a..a06a464f0497ba9a300ffb9b8f6e16d656ff68c4 100644 (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;
        }