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).
diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c
index 5a92d9b..2cdcf76 100644
--- a/src/cfgparse-global.c
+++ b/src/cfgparse-global.c
@@ -949,14 +949,14 @@
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;
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 2a7ed53..74218b5 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -922,7 +922,7 @@
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;
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 05b6d9e..50f43cd 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -345,14 +345,14 @@
}
/* 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 @@
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 @@
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;
}
diff --git a/src/cli.c b/src/cli.c
index 687796f..d1d1e96 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -359,7 +359,7 @@
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;
}
diff --git a/src/listener.c b/src/listener.c
index 2c885e9..9a79e6a 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -961,13 +961,13 @@
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;
}