[master] 6dd8f6d0e params: Add tweak_unit_orzero which allows 0 in addition to the uint range

Nils Goroll nils.goroll at uplex.de
Wed Feb 5 08:43:06 UTC 2025


commit 6dd8f6d0e85aa0052b7f08ec1641dbf50a2bf76d
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Feb 5 09:04:07 2025 +0100

    params: Add tweak_unit_orzero which allows 0 in addition to the uint range

diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h
index c88aef212..063ae7032 100644
--- a/bin/varnishd/mgt/mgt_param.h
+++ b/bin/varnishd/mgt/mgt_param.h
@@ -86,6 +86,7 @@ tweak_t tweak_thread_pool_min;
 tweak_t tweak_thread_pool_max;
 tweak_t tweak_timeout;
 tweak_t tweak_uint;
+tweak_t tweak_uint_orzero;
 tweak_t tweak_vcc_feature;
 tweak_t tweak_vsl_buffer;
 tweak_t tweak_vsl_mask;
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index be0af0b62..644dbab44 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -293,6 +293,21 @@ tweak_uint(struct vsb *vsb, const struct parspec *par, const char *arg)
 	    par->dyn_min_reason, par->dyn_max_reason));
 }
 
+int v_matchproto_(tweak_t)
+tweak_uint_orzero(struct vsb *vsb, const struct parspec *par, const char *arg)
+{
+	volatile unsigned *dest;
+
+	dest = par->priv;
+	if (arg != NULL && arg != JSON_FMT && ! strcmp(arg, "0")) {
+		VSB_cat(vsb, "0");
+		*dest = 0;
+		return (0);
+	}
+	return (tweak_generic_uint(vsb, dest, arg, par->min, par->max,
+	    par->dyn_min_reason, par->dyn_max_reason));
+}
+
 /*--------------------------------------------------------------------*/
 
 static void


More information about the varnish-commit mailing list