[master] 0dcf8360c Teach tweak_generic_uint more error reporting
Poul-Henning Kamp
phk at FreeBSD.org
Mon Oct 21 11:56:06 UTC 2019
commit 0dcf8360c5b3d21d928ab03589479d280c07d44f
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed Oct 16 11:49:00 2019 +0200
Teach tweak_generic_uint more error reporting
diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h
index 0e5258728..2d4936c94 100644
--- a/bin/varnishd/mgt/mgt_param.h
+++ b/bin/varnishd/mgt/mgt_param.h
@@ -72,7 +72,14 @@ tweak_t tweak_uint;
tweak_t tweak_vsl_buffer;
tweak_t tweak_vsl_reclen;
-int tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest,
+enum tweak_e {
+ TWEAK_OK,
+ TWEAK_ERR,
+ TWEAK_BELOW_MIN,
+ TWEAK_ABOVE_MAX,
+};
+
+enum tweak_e tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest,
const char *arg, const char *min, const char *max);
extern struct parspec mgt_parspec[]; /* mgt_param_tbl.c */
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index 6900f4e5f..fbb6933dc 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -156,7 +156,7 @@ tweak_bool(struct vsb *vsb, const struct parspec *par, const char *arg)
/*--------------------------------------------------------------------*/
-int
+enum tweak_e
tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest, const char *arg,
const char *min, const char *max)
{
@@ -169,7 +169,7 @@ tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest, const char *arg,
minv = strtoul(min, &p, 0);
if (*arg == '\0' || *p != '\0') {
VSB_printf(vsb, "Illegal Min: %s\n", min);
- return (-1);
+ return (TWEAK_ERR);
}
}
if (max != NULL) {
@@ -177,7 +177,7 @@ tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest, const char *arg,
maxv = strtoul(max, &p, 0);
if (*arg == '\0' || *p != '\0') {
VSB_printf(vsb, "Illegal Max: %s\n", max);
- return (-1);
+ return (TWEAK_ERR);
}
}
p = NULL;
@@ -187,16 +187,16 @@ tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest, const char *arg,
u = strtoul(arg, &p, 0);
if (*arg == '\0' || *p != '\0') {
VSB_printf(vsb, "Not a number (%s)\n", arg);
- return (-1);
+ return (TWEAK_ERR);
}
}
if (min != NULL && u < minv) {
VSB_printf(vsb, "Must be at least %s\n", min);
- return (-1);
+ return (TWEAK_BELOW_MIN);
}
if (max != NULL && u > maxv) {
VSB_printf(vsb, "Must be no more than %s\n", max);
- return (-1);
+ return (TWEAK_ABOVE_MAX);
}
*dest = u;
} else if (*dest == UINT_MAX && arg != JSON_FMT) {
@@ -204,7 +204,7 @@ tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest, const char *arg,
} else {
VSB_printf(vsb, "%u", *dest);
}
- return (0);
+ return (TWEAK_OK);
}
/*--------------------------------------------------------------------*/
More information about the varnish-commit
mailing list