Mailing List Archive

[6.0] c6406f242 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.
commit c6406f242d0725fbf90b988e4287f2d37378b856
Author: Poul-Henning Kamp <phk@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 394664939..bbb4a425f 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -123,7 +123,6 @@ mcf_askchild(struct cli *cli, const char * const *av, void *priv)
int i;
char *q;
unsigned u;
- struct vsb *vsb;

(void)priv;
/*
@@ -138,21 +137,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);
@@ -180,20 +177,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);
@@ -203,8 +194,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();
@@ -213,9 +203,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);
}

/*--------------------------------------------------------------------*/
@@ -370,6 +359,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"
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit