[master] 5698533 Build the CLI command we send to the child from av[] rather than rely on cli->cmd which is (by purpose) incomplete for here documents.

Poul-Henning Kamp phk at varnish-cache.org
Mon May 16 11:21:55 CEST 2011


commit 5698533c83b75d755f985e310a5a77a87112bd44
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 16 09:09:25 2011 +0000

    Build the CLI command we send to the child from av[] rather than
    rely on cli->cmd which is (by purpose) incomplete for here documents.

diff --git a/bin/varnishd/mgt_cli.c b/bin/varnishd/mgt_cli.c
index aed41b1..4390866 100644
--- a/bin/varnishd/mgt_cli.c
+++ b/bin/varnishd/mgt_cli.c
@@ -156,6 +156,7 @@ mcf_askchild(struct cli *cli, const char * const *av, void *priv)
 	int i;
 	char *q;
 	unsigned u;
+	struct vsb *vsb;
 
 	(void)priv;
 	/*
@@ -174,21 +175,22 @@ mcf_askchild(struct cli *cli, const char * const *av, void *priv)
 		    "Type 'help' for more info.");
 		return;
 	}
-	AN(cli->cmd);
-	i = write(cli_o, cli->cmd, strlen(cli->cmd));
-	if (i != strlen(cli->cmd)) {
-		cli_result(cli, CLIS_COMMS);
-		cli_out(cli, "CLI communication error");
-		MGT_Child_Cli_Fail();
-		return;
+	vsb = vsb_new_auto();
+	for (i = 1; av[i] != NULL; i++) {
+		vsb_quote(vsb, av[i], strlen(av[i]), 0);
+		vsb_putc(vsb, ' ');
 	}
-	i = write(cli_o, "\n", 1);
-	if (i != 1) {
+	vsb_putc(vsb, '\n');
+	AZ(vsb_finish(vsb));
+	i = write(cli_o, vsb_data(vsb), vsb_len(vsb));
+	if (i != vsb_len(vsb)) {
+		vsb_delete(vsb);
 		cli_result(cli, CLIS_COMMS);
 		cli_out(cli, "CLI communication error");
 		MGT_Child_Cli_Fail();
 		return;
 	}
+	vsb_delete(vsb);
 	(void)cli_readres(cli_i, &u, &q, params->cli_timeout);
 	cli_result(cli, u);
 	cli_out(cli, "%s", q);



More information about the varnish-commit mailing list