[master] 5d8a6c001 For CLI commands forwarded indirectly to the worker (via mgt_cli_askchild() as opposed to directly through mcf_askchild()), a truncated CLI response is not a failure.

Poul-Henning Kamp phk at FreeBSD.org
Mon Dec 2 22:10:07 UTC 2019


commit 5d8a6c0012c05c2f095c3a59e9f1dbc89b9f2c55
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Dec 2 22:05:30 2019 +0000

    For CLI commands forwarded indirectly to the worker (via
    mgt_cli_askchild() as opposed to directly through mcf_askchild()),
    a truncated CLI response is not a failure.
    
    Fixes #3038

diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index 4abcfe8a6..f40f35b3f 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -122,7 +122,6 @@ mcf_askchild(struct cli *cli, const char * const *av, void *priv)
 	int i;
 	char *q;
 	unsigned u;
-	struct vsb *vsb;
 
 	(void)priv;
 	/*
@@ -137,21 +136,19 @@ mcf_askchild(struct cli *cli, const char * const *av, void *priv)
 		    "Type 'help' for more info.");
 		return;
 	}
-	vsb = VSB_new_auto();
+	VSB_clear(cli_buf);
 	for (i = 1; av[i] != NULL; i++) {
-		VSB_quote(vsb, av[i], strlen(av[i]), 0);
-		VSB_putc(vsb, ' ');
+		VSB_quote(cli_buf, av[i], strlen(av[i]), 0);
+		VSB_putc(cli_buf, ' ');
 	}
-	VSB_putc(vsb, '\n');
-	AZ(VSB_finish(vsb));
-	if (VSB_tofile(cli_o, vsb)) {
-		VSB_destroy(&vsb);
+	VSB_putc(cli_buf, '\n');
+	AZ(VSB_finish(cli_buf));
+	if (VSB_tofile(cli_o, cli_buf)) {
 		VCLI_SetResult(cli, CLIS_COMMS);
 		VCLI_Out(cli, "CLI communication error");
 		MCH_Cli_Fail();
 		return;
 	}
-	VSB_destroy(&vsb);
 	if (VCLI_ReadResult(cli_i, &u, &q, mgt_param.cli_timeout))
 		MCH_Cli_Fail();
 	VCLI_SetResult(cli, u);
@@ -179,20 +176,14 @@ mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
 	va_list ap;
 	unsigned u;
 
-	if (cli_buf == NULL) {
-		cli_buf = VSB_new_auto();
-		AN(cli_buf);
-	} else {
-		VSB_clear(cli_buf);
-	}
+	AN(status);
+	VSB_clear(cli_buf);
 
 	if (resp != NULL)
 		*resp = NULL;
-	if (status != NULL)
-		*status = 0;
+	*status = 0;
 	if (cli_i < 0 || cli_o < 0) {
-		if (status != NULL)
-			*status = CLIS_CANT;
+		*status = CLIS_CANT;
 		return (CLIS_CANT);
 	}
 	va_start(ap, fmt);
@@ -202,8 +193,7 @@ mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
 	i = VSB_len(cli_buf);
 	assert(i > 0 && VSB_data(cli_buf)[i - 1] == '\n');
 	if (VSB_tofile(cli_o, cli_buf)) {
-		if (status != NULL)
-			*status = CLIS_COMMS;
+		*status = CLIS_COMMS;
 		if (resp != NULL)
 			*resp = strdup("CLI communication error");
 		MCH_Cli_Fail();
@@ -212,9 +202,8 @@ mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
 
 	if (VCLI_ReadResult(cli_i, &u, resp, mgt_param.cli_timeout))
 		MCH_Cli_Fail();
-	if (status != NULL)
-		*status = u;
-	return (u == CLIS_OK ? 0 : u);
+	*status = u;
+	return (u == CLIS_OK || u == CLIS_TRUNCATED ? 0 : u);
 }
 
 /*--------------------------------------------------------------------*/
@@ -369,6 +358,8 @@ mgt_cli_init_cls(void)
 	VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_proto);
 	VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_debug);
 	VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_askchild);
+	cli_buf = VSB_new_auto();
+	AN(cli_buf);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishtest/tests/r03038.vtc b/bin/varnishtest/tests/r03038.vtc
new file mode 100644
index 000000000..fd27faab8
--- /dev/null
+++ b/bin/varnishtest/tests/r03038.vtc
@@ -0,0 +1,25 @@
+varnishtest "vcl.list and cli_limit"
+
+server s1 { 
+} -start
+
+varnish v1 -vcl+backend { } -start
+varnish v1 -vcl+backend { } 
+varnish v1 -vcl+backend { }
+varnish v1 -vcl+backend { }
+varnish v1 -vcl+backend { }
+varnish v1 -vcl+backend { }
+varnish v1 -vcl+backend { }
+varnish v1 -vcl+backend { }
+varnish v1 -vcl+backend { }
+varnish v1 -vcl+backend { }
+
+varnish v1 -expect n_vcl_avail == 10
+
+varnish v1 -cliok "param.set cli_limit 128b"
+
+varnish v1 -clierr 201 "vcl.list"
+
+varnish v1 -stop
+
+varnish v1 -clierr 201 "vcl.list"


More information about the varnish-commit mailing list