[master] 6d0c94c Wean param tweakers from the CLI interface and just give them a VSB instead.

Poul-Henning Kamp phk at varnish-cache.org
Tue Nov 12 14:32:40 CET 2013


commit 6d0c94c34c0e471b12982b207857934ec4e6ea57
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Nov 12 13:32:20 2013 +0000

    Wean param tweakers from the CLI interface and just give them a
    VSB instead.

diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index e2a0297..8c32bcd 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -223,7 +223,7 @@ mcf_param_show(struct cli *cli, const char * const *av, void *priv)
 		} else {
 			VCLI_Out(cli, "%-*s", margin2, pp->name);
 		}
-		if (pp->func(cli, pp, NULL))
+		if (pp->func(cli->sb, pp, NULL))
 			VCLI_SetResult(cli, CLIS_PARAM);
 		if (pp->units != NULL && *pp->units != '\0')
 			VCLI_Out(cli, " [%s]\n", pp->units);
@@ -311,7 +311,7 @@ MCF_ParamSet(struct cli *cli, const char *param, const char *val)
 		VCLI_Out(cli, "parameter \"%s\" is protected.", param);
 		return;
 	}
-	if (pp->func(cli, pp, val))
+	if (pp->func(cli->sb, pp, val))
 		VCLI_SetResult(cli, CLIS_PARAM);
 
 	if (cli->result == CLIS_OK && heritage.param != NULL)
@@ -388,22 +388,37 @@ MCF_AddParams(const struct parspec *ps)
  * Set defaults for all parameters
  */
 
-static void
-MCF_SetDefaults(struct cli *cli)
+void
+MCF_InitParams(struct cli *cli)
 {
 	const struct parspec *pp;
-	int i;
-
-	for (i = 0; i < nparspec; i++) {
-		pp = parspecs[i];
-		if (cli != NULL)
-			VCLI_Out(cli,
-			    "Set Default for %s = %s\n", pp->name, pp->def);
-		if (pp->func(cli, pp, pp->def))
-			VCLI_SetResult(cli, CLIS_PARAM);
-		if (cli != NULL && cli->result != CLIS_OK)
-			return;
+	int i, j, err;
+	struct vsb *vsb;
+
+	/*
+	 * We try to set the default twice, and only failures the
+	 * second time around are fatal.  This allows for trivial
+	 * interdependencies.
+	 */
+	vsb = VSB_new_auto();
+	AN(vsb);
+	for (j = 0; j < 2; j++) {
+		err = 0;
+		for (i = 0; i < nparspec; i++) {
+			pp = parspecs[i];
+			VSB_clear(vsb);
+			VSB_printf(vsb,
+			    "FAILED to set default for param %s = %s\n",
+			    pp->name, pp->def);
+			err = pp->func(vsb, pp, pp->def);
+			AZ(VSB_finish(vsb));
+			if (err && j) {
+				VCLI_Out(cli, "%s", VSB_data(vsb));
+				VCLI_SetResult(cli, CLIS_CANT);
+			}
+		}
 	}
+	VSB_delete(vsb);
 }
 
 /*--------------------------------------------------------------------*/
@@ -420,17 +435,6 @@ MCF_CollectParams(void)
 /*--------------------------------------------------------------------*/
 
 void
-MCF_InitParams(struct cli *cli)
-{
-
-	/* XXX: We do this twice, to get past any interdependencies */
-	MCF_SetDefaults(NULL);
-	MCF_SetDefaults(cli);
-}
-
-/*--------------------------------------------------------------------*/
-
-void
 MCF_SetDefault(const char *param, const char *def)
 {
 	struct parspec *pn;
diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h
index b0bba39..c30394f 100644
--- a/bin/varnishd/mgt/mgt_param.h
+++ b/bin/varnishd/mgt/mgt_param.h
@@ -30,7 +30,7 @@
 
 struct parspec;
 
-typedef int tweak_t(struct cli *, const struct parspec *, const char *arg);
+typedef int tweak_t(struct vsb *, const struct parspec *, const char *arg);
 
 struct parspec {
 	const char	*name;
@@ -65,7 +65,7 @@ tweak_t tweak_uint;
 tweak_t tweak_user;
 tweak_t tweak_waiter;
 
-int tweak_generic_uint(struct cli *cli,
+int tweak_generic_uint(struct vsb *vsb,
     volatile unsigned *dest, const char *arg, unsigned min, unsigned max);
 
 /* mgt_param_tbl.c */
diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c
index 24276f1..57b26ce 100644
--- a/bin/varnishd/mgt/mgt_param_bits.c
+++ b/bin/varnishd/mgt/mgt_param_bits.c
@@ -38,9 +38,6 @@
 #include "mgt/mgt_param.h"
 
 #include "vav.h"
-#include "vcli.h"
-#include "vcli_common.h"
-#include "vcli_priv.h"
 
 #include "vapi/vsl_int.h"
 
@@ -67,7 +64,7 @@ bit(uint8_t *p, unsigned no, enum bit_do act)
  */
 
 static int
-bit_tweak(struct cli *cli, uint8_t *p, unsigned l, const char *arg,
+bit_tweak(struct vsb *vsb, uint8_t *p, unsigned l, const char *arg,
     const char * const *tags, const char *desc, const char *sign)
 {
 	int i, n;
@@ -77,14 +74,14 @@ bit_tweak(struct cli *cli, uint8_t *p, unsigned l, const char *arg,
 
 	av = VAV_Parse(arg, &n, ARGV_COMMA);
 	if (av[0] != NULL) {
-		VCLI_Out(cli, "Cannot parse: %s\n", av[0]);
+		VSB_printf(vsb, "Cannot parse: %s\n", av[0]);
 		VAV_Free(av);
 		return (-1);
 	}
 	for (i = 1; av[i] != NULL; i++) {
 		s = av[i];
 		if (*s != '-' && *s != '+') {
-			VCLI_Out(cli, "Missing '+' or '-' (%s)\n", s);
+			VSB_printf(vsb, "Missing '+' or '-' (%s)\n", s);
 			VAV_Free(av);
 			return (-1);
 		}
@@ -93,7 +90,7 @@ bit_tweak(struct cli *cli, uint8_t *p, unsigned l, const char *arg,
 				break;
 		}
 		if (tags[j] == NULL) {
-			VCLI_Out(cli, "Unknown %s (%s)\n", desc, s);
+			VSB_printf(vsb, "Unknown %s (%s)\n", desc, s);
 			VAV_Free(av);
 			return (-1);
 		}
@@ -120,7 +117,7 @@ static const char * const VSL_tags[256] = {
 };
 
 static int
-tweak_vsl_mask(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_vsl_mask(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	unsigned j;
 	const char *s;
@@ -134,7 +131,7 @@ tweak_vsl_mask(struct cli *cli, const struct parspec *par, const char *arg)
 			(void)bit(mgt_param.vsl_mask, SLT_WorkThread, BSET);
 			(void)bit(mgt_param.vsl_mask, SLT_Hash, BSET);
 		} else {
-			return (bit_tweak(cli, mgt_param.vsl_mask,
+			return (bit_tweak(vsb, mgt_param.vsl_mask,
 			    SLT__Reserved, arg, VSL_tags,
 			    "VSL tag", "-"));
 		}
@@ -142,12 +139,12 @@ tweak_vsl_mask(struct cli *cli, const struct parspec *par, const char *arg)
 		s = "";
 		for (j = 0; j < (unsigned)SLT__Reserved; j++) {
 			if (bit(mgt_param.vsl_mask, j, BTST)) {
-				VCLI_Out(cli, "%s-%s", s, VSL_tags[j]);
+				VSB_printf(vsb, "%s-%s", s, VSL_tags[j]);
 				s = ",";
 			}
 		}
 		if (*s == '\0')
-			VCLI_Out(cli, "(all enabled)");
+			VSB_printf(vsb, "(all enabled)");
 	}
 	return (0);
 }
@@ -164,7 +161,7 @@ static const char * const debug_tags[] = {
 };
 
 static int
-tweak_debug(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_debug(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	const char *s;
 	unsigned j;
@@ -175,19 +172,19 @@ tweak_debug(struct cli *cli, const struct parspec *par, const char *arg)
 			memset(mgt_param.debug_bits,
 			    0, sizeof mgt_param.debug_bits);
 		} else {
-			return (bit_tweak(cli, mgt_param.debug_bits,
+			return (bit_tweak(vsb, mgt_param.debug_bits,
 			    DBG_Reserved, arg, debug_tags, "debug bit", "+"));
 		}
 	} else {
 		s = "";
 		for (j = 0; j < (unsigned)DBG_Reserved; j++) {
 			if (bit(mgt_param.debug_bits, j, BTST)) {
-				VCLI_Out(cli, "%s+%s", s, debug_tags[j]);
+				VSB_printf(vsb, "%s+%s", s, debug_tags[j]);
 				s = ",";
 			}
 		}
 		if (*s == '\0')
-			VCLI_Out(cli, "none");
+			VSB_printf(vsb, "none");
 	}
 	return (0);
 }
@@ -204,7 +201,7 @@ static const char * const feature_tags[] = {
 };
 
 static int
-tweak_feature(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_feature(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	const char *s;
 	unsigned j;
@@ -215,7 +212,7 @@ tweak_feature(struct cli *cli, const struct parspec *par, const char *arg)
 			memset(mgt_param.feature_bits,
 			    0, sizeof mgt_param.feature_bits);
 		} else {
-			return (bit_tweak(cli, mgt_param.feature_bits,
+			return (bit_tweak(vsb, mgt_param.feature_bits,
 			    FEATURE_Reserved, arg, feature_tags,
 			    "feature bit", "+"));
 		}
@@ -223,12 +220,12 @@ tweak_feature(struct cli *cli, const struct parspec *par, const char *arg)
 		s = "";
 		for (j = 0; j < (unsigned)FEATURE_Reserved; j++) {
 			if (bit(mgt_param.feature_bits, j, BTST)) {
-				VCLI_Out(cli, "%s+%s", s, feature_tags[j]);
+				VSB_printf(vsb, "%s+%s", s, feature_tags[j]);
 				s = ",";
 			}
 		}
 		if (*s == '\0')
-			VCLI_Out(cli, "none");
+			VSB_printf(vsb, "none");
 	}
 	return (0);
 }
diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c
index d93914d..d6247d7 100644
--- a/bin/varnishd/mgt/mgt_param_tbl.c
+++ b/bin/varnishd/mgt/mgt_param_tbl.c
@@ -65,7 +65,7 @@ const struct parspec mgt_parspec[] = {
 		"The TTL assigned to objects if neither the backend nor "
 		"the VCL code assigns one.",
 		OBJ_STICKY,
-		"120", "seconds" },
+		"20", "seconds" },
 	{ "default_grace", tweak_timeout_double, &mgt_param.default_grace,
 		0, UINT_MAX,
 		"Default grace period.  We will deliver an object "
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index ee30f54..fa2e866 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -59,37 +59,37 @@
 /*--------------------------------------------------------------------*/
 
 static int
-tweak_generic_timeout(struct cli *cli, volatile unsigned *dst, const char *arg)
+tweak_generic_timeout(struct vsb *vsb, volatile unsigned *dst, const char *arg)
 {
 	unsigned u;
 
 	if (arg != NULL) {
 		u = strtoul(arg, NULL, 0);
 		if (u == 0) {
-			VCLI_Out(cli, "Timeout must be greater than zero\n");
+			VSB_printf(vsb, "Timeout must be greater than zero\n");
 			return (-1);
 		}
 		*dst = u;
 	} else
-		VCLI_Out(cli, "%u", *dst);
+		VSB_printf(vsb, "%u", *dst);
 	return (0);
 }
 
 /*--------------------------------------------------------------------*/
 
 int
-tweak_timeout(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_timeout(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	volatile unsigned *dest;
 
 	dest = par->priv;
-	return (tweak_generic_timeout(cli, dest, arg));
+	return (tweak_generic_timeout(vsb, dest, arg));
 }
 
 /*--------------------------------------------------------------------*/
 
 static int
-tweak_generic_timeout_double(struct cli *cli, volatile double *dest,
+tweak_generic_timeout_double(struct vsb *vsb, volatile double *dest,
     const char *arg, double min, double max)
 {
 	double u;
@@ -99,40 +99,40 @@ tweak_generic_timeout_double(struct cli *cli, volatile double *dest,
 		p = NULL;
 		u = strtod(arg, &p);
 		if (*arg == '\0' || *p != '\0') {
-			VCLI_Out(cli, "Not a number(%s)\n", arg);
+			VSB_printf(vsb, "Not a number(%s)\n", arg);
 			return (-1);
 		}
 		if (u < min) {
-			VCLI_Out(cli,
+			VSB_printf(vsb,
 			    "Timeout must be greater or equal to %.g\n", min);
 			return (-1);
 		}
 		if (u > max) {
-			VCLI_Out(cli,
+			VSB_printf(vsb,
 			    "Timeout must be less than or equal to %.g\n", max);
 			return (-1);
 		}
 		*dest = u;
 	} else
-		VCLI_Out(cli, "%.6f", *dest);
+		VSB_printf(vsb, "%.6f", *dest);
 	return (0);
 }
 
 int
-tweak_timeout_double(struct cli *cli, const struct parspec *par,
+tweak_timeout_double(struct vsb *vsb, const struct parspec *par,
     const char *arg)
 {
 	volatile double *dest;
 
 	dest = par->priv;
-	return (tweak_generic_timeout_double(cli, dest, arg,
+	return (tweak_generic_timeout_double(vsb, dest, arg,
 	    par->min, par->max));
 }
 
 /*--------------------------------------------------------------------*/
 
 int
-tweak_generic_double(struct cli *cli, const struct parspec *par,
+tweak_generic_double(struct vsb *vsb, const struct parspec *par,
     const char *arg)
 {
 	volatile double *dest;
@@ -144,32 +144,32 @@ tweak_generic_double(struct cli *cli, const struct parspec *par,
 		p = NULL;
 		u = strtod(arg, &p);
 		if (*p != '\0') {
-			VCLI_Out(cli,
+			VSB_printf(vsb,
 			    "Not a number (%s)\n", arg);
 			return (-1);
 		}
 		if (u < par->min) {
-			VCLI_Out(cli,
+			VSB_printf(vsb,
 			    "Must be greater or equal to %.g\n",
 				 par->min);
 			return (-1);
 		}
 		if (u > par->max) {
-			VCLI_Out(cli,
+			VSB_printf(vsb,
 			    "Must be less than or equal to %.g\n",
 				 par->max);
 			return (-1);
 		}
 		*dest = u;
 	} else
-		VCLI_Out(cli, "%f", *dest);
+		VSB_printf(vsb, "%f", *dest);
 	return (0);
 }
 
 /*--------------------------------------------------------------------*/
 
 int
-tweak_bool(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_bool(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	volatile unsigned *dest;
 	int mode = 0;
@@ -196,16 +196,16 @@ tweak_bool(struct cli *cli, const struct parspec *par, const char *arg)
 		else if (!strcasecmp(arg, "true"))
 			*dest = 1;
 		else {
-			VCLI_Out(cli,
+			VSB_printf(vsb, "%s",
 			    mode ?
 				"use \"on\" or \"off\"\n" :
 				"use \"true\" or \"false\"\n");
 			return (-1);
 		}
 	} else if (mode) {
-		VCLI_Out(cli, *dest ? "on" : "off");
+		VSB_printf(vsb, "%s", *dest ? "on" : "off");
 	} else {
-		VCLI_Out(cli, *dest ? "true" : "false");
+		VSB_printf(vsb, "%s", *dest ? "true" : "false");
 	}
 	return (0);
 }
@@ -213,7 +213,7 @@ tweak_bool(struct cli *cli, const struct parspec *par, const char *arg)
 /*--------------------------------------------------------------------*/
 
 int
-tweak_generic_uint(struct cli *cli, volatile unsigned *dest, const char *arg,
+tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest, const char *arg,
     unsigned min, unsigned max)
 {
 	unsigned u;
@@ -226,23 +226,23 @@ tweak_generic_uint(struct cli *cli, volatile unsigned *dest, const char *arg,
 		else {
 			u = strtoul(arg, &p, 0);
 			if (*arg == '\0' || *p != '\0') {
-				VCLI_Out(cli, "Not a number (%s)\n", arg);
+				VSB_printf(vsb, "Not a number (%s)\n", arg);
 				return (-1);
 			}
 		}
 		if (u < min) {
-			VCLI_Out(cli, "Must be at least %u\n", min);
+			VSB_printf(vsb, "Must be at least %u\n", min);
 			return (-1);
 		}
 		if (u > max) {
-			VCLI_Out(cli, "Must be no more than %u\n", max);
+			VSB_printf(vsb, "Must be no more than %u\n", max);
 			return (-1);
 		}
 		*dest = u;
 	} else if (*dest == UINT_MAX) {
-		VCLI_Out(cli, "unlimited");
+		VSB_printf(vsb, "unlimited");
 	} else {
-		VCLI_Out(cli, "%u", *dest);
+		VSB_printf(vsb, "%u", *dest);
 	}
 	return (0);
 }
@@ -250,12 +250,12 @@ tweak_generic_uint(struct cli *cli, volatile unsigned *dest, const char *arg,
 /*--------------------------------------------------------------------*/
 
 int
-tweak_uint(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_uint(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	volatile unsigned *dest;
 
 	dest = par->priv;
-	(void)tweak_generic_uint(cli, dest, arg,
+	(void)tweak_generic_uint(vsb, dest, arg,
 	    (uint)par->min, (uint)par->max);
 	return (0);
 }
@@ -263,30 +263,30 @@ tweak_uint(struct cli *cli, const struct parspec *par, const char *arg)
 /*--------------------------------------------------------------------*/
 
 static void
-fmt_bytes(struct cli *cli, uintmax_t t)
+fmt_bytes(struct vsb *vsb, uintmax_t t)
 {
 	const char *p;
 
 	if (t & 0xff) {
-		VCLI_Out(cli, "%jub", t);
+		VSB_printf(vsb, "%jub", t);
 		return;
 	}
 	for (p = "kMGTPEZY"; *p; p++) {
 		if (t & 0x300) {
-			VCLI_Out(cli, "%.2f%c", t / 1024.0, *p);
+			VSB_printf(vsb, "%.2f%c", t / 1024.0, *p);
 			return;
 		}
 		t /= 1024;
 		if (t & 0x0ff) {
-			VCLI_Out(cli, "%ju%c", t, *p);
+			VSB_printf(vsb, "%ju%c", t, *p);
 			return;
 		}
 	}
-	VCLI_Out(cli, "(bogus number)");
+	VSB_printf(vsb, "(bogus number)");
 }
 
 static int
-tweak_generic_bytes(struct cli *cli, volatile ssize_t *dest, const char *arg,
+tweak_generic_bytes(struct vsb *vsb, volatile ssize_t *dest, const char *arg,
     double min, double max)
 {
 	uintmax_t r;
@@ -295,32 +295,32 @@ tweak_generic_bytes(struct cli *cli, volatile ssize_t *dest, const char *arg,
 	if (arg != NULL) {
 		p = VNUM_2bytes(arg, &r, 0);
 		if (p != NULL) {
-			VCLI_Out(cli, "Could not convert to bytes.\n");
-			VCLI_Out(cli, "%s\n", p);
-			VCLI_Out(cli,
+			VSB_printf(vsb, "Could not convert to bytes.\n");
+			VSB_printf(vsb, "%s\n", p);
+			VSB_printf(vsb,
 			    "  Try something like '80k' or '120M'\n");
 			return (-1);
 		}
 		if ((uintmax_t)((ssize_t)r) != r) {
-			fmt_bytes(cli, r);
-			VCLI_Out(cli, " is too large for this architecture.\n");
+			fmt_bytes(vsb, r);
+			VSB_printf(vsb, " is too large for this architecture.\n");
 			return (-1);
 		}
 		if (max != 0. && r > max) {
-			VCLI_Out(cli, "Must be no more than ");
-			fmt_bytes(cli, (uintmax_t)max);
-			VCLI_Out(cli, "\n");
+			VSB_printf(vsb, "Must be no more than ");
+			fmt_bytes(vsb, (uintmax_t)max);
+			VSB_printf(vsb, "\n");
 			return (-1);
 		}
 		if (r < min) {
-			VCLI_Out(cli, "Must be at least ");
-			fmt_bytes(cli, (uintmax_t)min);
-			VCLI_Out(cli, "\n");
+			VSB_printf(vsb, "Must be at least ");
+			fmt_bytes(vsb, (uintmax_t)min);
+			VSB_printf(vsb, "\n");
 			return (-1);
 		}
 		*dest = r;
 	} else {
-		fmt_bytes(cli, *dest);
+		fmt_bytes(vsb, *dest);
 	}
 	return (0);
 }
@@ -328,20 +328,20 @@ tweak_generic_bytes(struct cli *cli, volatile ssize_t *dest, const char *arg,
 /*--------------------------------------------------------------------*/
 
 int
-tweak_bytes(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_bytes(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	volatile ssize_t *dest;
 
 	assert(par->min >= 0);
 	dest = par->priv;
-	return (tweak_generic_bytes(cli, dest, arg, par->min, par->max));
+	return (tweak_generic_bytes(vsb, dest, arg, par->min, par->max));
 }
 
 
 /*--------------------------------------------------------------------*/
 
 int
-tweak_bytes_u(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_bytes_u(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	volatile unsigned *d1;
 	volatile ssize_t dest;
@@ -350,7 +350,7 @@ tweak_bytes_u(struct cli *cli, const struct parspec *par, const char *arg)
 	assert(par->min >= 0);
 	d1 = par->priv;
 	dest = *d1;
-	if (tweak_generic_bytes(cli, &dest, arg, par->min, par->max))
+	if (tweak_generic_bytes(vsb, &dest, arg, par->min, par->max))
 		return (-1);
 	*d1 = dest;
 	return (0);
@@ -365,7 +365,7 @@ tweak_bytes_u(struct cli *cli, const struct parspec *par, const char *arg)
  */
 
 int
-tweak_user(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_user(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	struct passwd *pw;
 
@@ -374,7 +374,7 @@ tweak_user(struct cli *cli, const struct parspec *par, const char *arg)
 		if (*arg != '\0') {
 			pw = getpwnam(arg);
 			if (pw == NULL) {
-				VCLI_Out(cli, "Unknown user");
+				VSB_printf(vsb, "Unknown user");
 				return(-1);
 			}
 			REPLACE(mgt_param.user, pw->pw_name);
@@ -383,9 +383,9 @@ tweak_user(struct cli *cli, const struct parspec *par, const char *arg)
 			mgt_param.uid = getuid();
 		}
 	} else if (mgt_param.user) {
-		VCLI_Out(cli, "%s (%d)", mgt_param.user, (int)mgt_param.uid);
+		VSB_printf(vsb, "%s (%d)", mgt_param.user, (int)mgt_param.uid);
 	} else {
-		VCLI_Out(cli, "UID %d", (int)mgt_param.uid);
+		VSB_printf(vsb, "UID %d", (int)mgt_param.uid);
 	}
 	return (0);
 }
@@ -395,7 +395,7 @@ tweak_user(struct cli *cli, const struct parspec *par, const char *arg)
  */
 
 int
-tweak_group(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_group(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	struct group *gr;
 
@@ -404,7 +404,7 @@ tweak_group(struct cli *cli, const struct parspec *par, const char *arg)
 		if (*arg != '\0') {
 			gr = getgrnam(arg);
 			if (gr == NULL) {
-				VCLI_Out(cli, "Unknown group");
+				VSB_printf(vsb, "Unknown group");
 				return(-1);
 			}
 			REPLACE(mgt_param.group, gr->gr_name);
@@ -413,9 +413,9 @@ tweak_group(struct cli *cli, const struct parspec *par, const char *arg)
 			mgt_param.gid = getgid();
 		}
 	} else if (mgt_param.group) {
-		VCLI_Out(cli, "%s (%d)", mgt_param.group, (int)mgt_param.gid);
+		VSB_printf(vsb, "%s (%d)", mgt_param.group, (int)mgt_param.gid);
 	} else {
-		VCLI_Out(cli, "GID %d", (int)mgt_param.gid);
+		VSB_printf(vsb, "GID %d", (int)mgt_param.gid);
 	}
 	return (0);
 }
@@ -437,7 +437,7 @@ clean_listen_sock_head(struct listen_sock_head *lsh)
 }
 
 int
-tweak_listen_address(struct cli *cli, const struct parspec *par,
+tweak_listen_address(struct vsb *vsb, const struct parspec *par,
     const char *arg)
 {
 	char **av;
@@ -447,22 +447,22 @@ tweak_listen_address(struct cli *cli, const struct parspec *par,
 
 	(void)par;
 	if (arg == NULL) {
-		VCLI_Quote(cli, mgt_param.listen_address);
+		VSB_quote(vsb, mgt_param.listen_address, -1, 0);
 		return (0);
 	}
 
 	av = VAV_Parse(arg, NULL, ARGV_COMMA);
 	if (av == NULL) {
-		VCLI_Out(cli, "Parse error: out of memory");
+		VSB_printf(vsb, "Parse error: out of memory");
 		return(-1);
 	}
 	if (av[0] != NULL) {
-		VCLI_Out(cli, "Parse error: %s", av[0]);
+		VSB_printf(vsb, "Parse error: %s", av[0]);
 		VAV_Free(av);
 		return(-1);
 	}
 	if (av[1] == NULL) {
-		VCLI_Out(cli, "Empty listen address");
+		VSB_printf(vsb, "Empty listen address");
 		VAV_Free(av);
 		return(-1);
 	}
@@ -473,8 +473,8 @@ tweak_listen_address(struct cli *cli, const struct parspec *par,
 
 		n = VSS_resolve(av[i], "http", &ta);
 		if (n == 0) {
-			VCLI_Out(cli, "Invalid listen address ");
-			VCLI_Quote(cli, av[i]);
+			VSB_printf(vsb, "Invalid listen address ");
+			VSB_quote(vsb, av[i], -1, 0);
 			retval = -1;
 			break;
 		}
@@ -513,14 +513,14 @@ tweak_listen_address(struct cli *cli, const struct parspec *par,
 /*--------------------------------------------------------------------*/
 
 int
-tweak_string(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_string(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	char **p = TRUST_ME(par->priv);
 
 	AN(p);
 	/* XXX should have tweak_generic_string */
 	if (arg == NULL) {
-		VCLI_Quote(cli, *p);
+		VSB_quote(vsb, *p, -1, 0);
 	} else {
 		REPLACE(*p, arg);
 	}
@@ -530,18 +530,18 @@ tweak_string(struct cli *cli, const struct parspec *par, const char *arg)
 /*--------------------------------------------------------------------*/
 
 int
-tweak_waiter(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_waiter(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 
 	/* XXX should have tweak_generic_string */
 	(void)par;
-	return (WAIT_tweak_waiter(cli, arg));
+	return (WAIT_tweak_waiter(vsb, arg));
 }
 
 /*--------------------------------------------------------------------*/
 
 int
-tweak_poolparam(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_poolparam(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	volatile struct poolparam *pp, px;
 	char **av;
@@ -549,38 +549,38 @@ tweak_poolparam(struct cli *cli, const struct parspec *par, const char *arg)
 
 	pp = par->priv;
 	if (arg == NULL) {
-		VCLI_Out(cli, "%u,%u,%g",
+		VSB_printf(vsb, "%u,%u,%g",
 		    pp->min_pool, pp->max_pool, pp->max_age);
 	} else {
 		av = VAV_Parse(arg, NULL, ARGV_COMMA);
 		do {
 			if (av[0] != NULL) {
-				VCLI_Out(cli, "Parse error: %s", av[0]);
+				VSB_printf(vsb, "Parse error: %s", av[0]);
 				retval = -1;
 				break;
 			}
 			if (av[1] == NULL || av[2] == NULL || av[3] == NULL) {
-				VCLI_Out(cli,
+				VSB_printf(vsb,
 				    "Three fields required:"
 				    " min_pool, max_pool and max_age\n");
 				retval = -1;
 				break;
 			}
 			px = *pp;
-			retval = tweak_generic_uint(cli, &px.min_pool, av[1],
+			retval = tweak_generic_uint(vsb, &px.min_pool, av[1],
 			    (uint)par->min, (uint)par->max);
 			if (retval)
 				break;
-			retval = tweak_generic_uint(cli, &px.max_pool, av[2],
+			retval = tweak_generic_uint(vsb, &px.max_pool, av[2],
 			    (uint)par->min, (uint)par->max);
 			if (retval)
 				break;
-			retval = tweak_generic_timeout_double(cli,
+			retval = tweak_generic_timeout_double(vsb,
 			    &px.max_age, av[3], 0, 1e6);
 			if (retval)
 				break;
 			if (px.min_pool > px.max_pool) {
-				VCLI_Out(cli,
+				VSB_printf(vsb,
 				    "min_pool cannot be larger"
 				    " than max_pool\n");
 				retval = -1;
diff --git a/bin/varnishd/mgt/mgt_pool.c b/bin/varnishd/mgt/mgt_pool.c
index 8096170..61b8425 100644
--- a/bin/varnishd/mgt/mgt_pool.c
+++ b/bin/varnishd/mgt/mgt_pool.c
@@ -55,11 +55,11 @@
 /*--------------------------------------------------------------------*/
 
 static int
-tweak_thread_pool_min(struct cli *cli, const struct parspec *par,
+tweak_thread_pool_min(struct vsb *vsb, const struct parspec *par,
     const char *arg)
 {
 
-	return (tweak_generic_uint(cli, &mgt_param.wthread_min, arg,
+	return (tweak_generic_uint(vsb, &mgt_param.wthread_min, arg,
 	    (unsigned)par->min, mgt_param.wthread_max));
 }
 
@@ -70,14 +70,14 @@ tweak_thread_pool_min(struct cli *cli, const struct parspec *par,
  */
 
 static int
-tweak_stack_size(struct cli *cli, const struct parspec *par,
+tweak_stack_size(struct vsb *vsb, const struct parspec *par,
     const char *arg)
 {
 	ssize_t low;
 
 	low = sysconf(_SC_THREAD_STACK_MIN);
 
-	if (tweak_bytes(cli, par, arg))
+	if (tweak_bytes(vsb, par, arg))
 		return (-1);
 	if (mgt_param.wthread_stacksize < low)
 		mgt_param.wthread_stacksize = low;
@@ -87,12 +87,12 @@ tweak_stack_size(struct cli *cli, const struct parspec *par,
 /*--------------------------------------------------------------------*/
 
 static int
-tweak_thread_pool_max(struct cli *cli, const struct parspec *par,
+tweak_thread_pool_max(struct vsb *vsb, const struct parspec *par,
     const char *arg)
 {
 
 	(void)par;
-	return (tweak_generic_uint(cli, &mgt_param.wthread_max, arg,
+	return (tweak_generic_uint(vsb, &mgt_param.wthread_max, arg,
 	    mgt_param.wthread_min, UINT_MAX));
 }
 
diff --git a/bin/varnishd/waiter/mgt_waiter.c b/bin/varnishd/waiter/mgt_waiter.c
index 0d841a1..c36e089 100644
--- a/bin/varnishd/waiter/mgt_waiter.c
+++ b/bin/varnishd/waiter/mgt_waiter.c
@@ -36,7 +36,6 @@
 #include "common/common.h"
 
 #include "waiter/waiter.h"
-#include "vcli_priv.h"
 
 static const struct waiter *const vca_waiters[] = {
     #if defined(HAVE_KQUEUE)
@@ -55,7 +54,7 @@ static const struct waiter *const vca_waiters[] = {
 struct waiter const *waiter;
 
 int
-WAIT_tweak_waiter(struct cli *cli, const char *arg)
+WAIT_tweak_waiter(struct vsb *vsb, const char *arg)
 {
 	int i;
 
@@ -63,15 +62,15 @@ WAIT_tweak_waiter(struct cli *cli, const char *arg)
 
 	if (arg == NULL) {
 		if (waiter == NULL)
-			VCLI_Out(cli, "default");
+			VSB_printf(vsb, "default");
 		else
-			VCLI_Out(cli, "%s", waiter->name);
+			VSB_printf(vsb, "%s", waiter->name);
 
-		VCLI_Out(cli, " (possible values: ");
+		VSB_printf(vsb, " (possible values: ");
 		for (i = 0; vca_waiters[i] != NULL; i++)
-			VCLI_Out(cli, "%s%s", i == 0 ? "" : ", ",
+			VSB_printf(vsb, "%s%s", i == 0 ? "" : ", ",
 			    vca_waiters[i]->name);
-		VCLI_Out(cli, ")");
+		VSB_printf(vsb, ")");
 		return(0);
 	}
 	if (!strcmp(arg, WAITER_DEFAULT)) {
@@ -84,6 +83,6 @@ WAIT_tweak_waiter(struct cli *cli, const char *arg)
 			return(0);
 		}
 	}
-	VCLI_Out(cli, "Unknown waiter");
+	VSB_printf(vsb, "Unknown waiter");
 	return (-1);
 }
diff --git a/bin/varnishd/waiter/waiter.h b/bin/varnishd/waiter/waiter.h
index 5f1a546..5e8e56b 100644
--- a/bin/varnishd/waiter/waiter.h
+++ b/bin/varnishd/waiter/waiter.h
@@ -43,7 +43,7 @@ struct waiter {
 
 /* mgt_waiter.c */
 extern struct waiter const * waiter;
-int WAIT_tweak_waiter(struct cli *cli, const char *arg);
+int WAIT_tweak_waiter(struct vsb *vsb, const char *arg);
 
 #if defined(HAVE_EPOLL_CTL)
 extern const struct waiter waiter_epoll;



More information about the varnish-commit mailing list