Skip to content
Permalink
Browse files

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
  • Loading branch information
bsdphk committed Dec 2, 2019
1 parent 32c7d71 commit 5d8a6c0012c05c2f095c3a59e9f1dbc89b9f2c55
Showing with 40 additions and 24 deletions.
  1. +15 −24 bin/varnishd/mgt/mgt_cli.c
  2. +25 −0 bin/varnishtest/tests/r03038.vtc
@@ -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);
}

/*--------------------------------------------------------------------
@@ -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"

0 comments on commit 5d8a6c0

Please sign in to comment.
You can’t perform that action at this time.