[master] 8fa24e2 Match output for boolean params to the default value so we can choose to present on/off or true/false, depending on what makes most sense.

Poul-Henning Kamp phk at varnish-cache.org
Thu Jan 10 11:35:03 CET 2013


commit 8fa24e2043d62401ebb8bc22508b6b72613a32c9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jan 10 10:34:13 2013 +0000

    Match output for boolean params to the default value so
    we can choose to present on/off or true/false, depending on what
    makes most sense.
    
    Fixes	#1245

diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 6ce53eb..2966d09 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -187,9 +187,16 @@ tweak_generic_double(struct cli *cli, const struct parspec *par,
 
 /*--------------------------------------------------------------------*/
 
-static void
-tweak_generic_bool(struct cli *cli, volatile unsigned *dest, const char *arg)
+void
+tweak_bool(struct cli *cli, const struct parspec *par, const char *arg)
 {
+	volatile unsigned *dest;
+	int mode = 0;
+
+	if (!strcmp(par->def, "off") || !strcmp(par->def, "on"))
+		mode = 1;
+
+	dest = par->priv;
 	if (arg != NULL) {
 		if (!strcasecmp(arg, "off"))
 			*dest = 0;
@@ -208,23 +215,18 @@ tweak_generic_bool(struct cli *cli, volatile unsigned *dest, const char *arg)
 		else if (!strcasecmp(arg, "true"))
 			*dest = 1;
 		else {
-			VCLI_Out(cli, "use \"on\" or \"off\"\n");
+			VCLI_Out(cli,
+			    mode ? 
+				"use \"on\" or \"off\"\n" :
+				"use \"true\" or \"false\"\n");
 			VCLI_SetResult(cli, CLIS_PARAM);
 			return;
 		}
-	} else
+	} else if (mode) {
 		VCLI_Out(cli, *dest ? "on" : "off");
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-tweak_bool(struct cli *cli, const struct parspec *par, const char *arg)
-{
-	volatile unsigned *dest;
-
-	dest = par->priv;
-	tweak_generic_bool(cli, dest, arg);
+	} else {
+		VCLI_Out(cli, *dest ? "true" : "false");
+	}
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c
index 0e4e561..cb54111 100644
--- a/bin/varnishd/mgt/mgt_param_tbl.c
+++ b/bin/varnishd/mgt/mgt_param_tbl.c
@@ -556,7 +556,7 @@ const struct parspec mgt_parspec[] = {
 		"Disable this if you have very high hitrates and want"
 		"to save the memory of one busyobj per worker thread.",
 		0,
-		"false", ""},
+		"off", "bool"},
 
 	{ "pool_vbc", tweak_poolparam, &mgt_param.vbc_pool, 0, 10000,
 		"Parameters for backend connection memory pool.\n"
@@ -582,9 +582,9 @@ const struct parspec mgt_parspec[] = {
 
 	{ "obj_readonly", tweak_bool, &mgt_param.obj_readonly, 0, 0,
 		"If set, we do not update obj.hits and obj.lastuse to"
-		"avoid dirtying VM pages associated with cached objects.",
+		" avoid dirtying VM pages associated with cached objects.",
 		0,
-		"false", ""},
+		"false", "bool"},
 
 	{ NULL, NULL, NULL }
 };



More information about the varnish-commit mailing list