Commit ec62e71f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a "banner" command to the CLI interface.

Add a parameter "cli_banner" (default on) which injects an implicit
"banner" CLI command on all cli connections when opened.

The net result is that you get a CLI response when you connect to
the CLI ports:

	200 193     
	-----------------------------
	Varnish HTTP accelerator CLI.
	-----------------------------
	Type 'help' for command list.
	Type 'quit' to close CLI session.
	Type 'start' to launch worker process.

Presently the contents of the CLI response is "undefined", in the
sense that you should not programatically depend on anything besides
the "200" reply code.





git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3762 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 89a75b54
......@@ -195,6 +195,9 @@ struct params {
/* Get rid of duplicate purges */
unsigned purge_dups;
/* CLI banner */
unsigned cli_banner;
};
extern volatile struct params *params;
......
......@@ -553,9 +553,7 @@ mgt_run(int dflag, const char *T_arg)
start_child(NULL);
if (child_state == CH_STOPPED)
exit(2);
} else
fprintf(stderr,
"Debugging mode, enter \"start\" to start child\n");
}
i = vev_schedule(mgt_evb);
if (i != 0)
......
......@@ -126,9 +126,28 @@ mcf_close(struct cli *cli, const char *const *av, void *priv)
/*--------------------------------------------------------------------*/
static void
mcf_banner(struct cli *cli, const char *const *av, void *priv)
{
(void)av;
(void)priv;
cli_out(cli, "-----------------------------\n");
cli_out(cli, "Varnish HTTP accelerator CLI.\n");
cli_out(cli, "-----------------------------\n");
cli_out(cli, "Type 'help' for command list.\n");
cli_out(cli, "Type 'quit' to close CLI session.\n");
if (child_pid < 0)
cli_out(cli, "Type 'start' to launch worker process.\n");
cli_result(cli, CLIS_OK);
}
/*--------------------------------------------------------------------*/
/* XXX: what order should this list be in ? */
static struct cli_proto cli_proto[] = {
{ CLI_HELP, mcf_help, cli_proto },
{ CLI_BANNER, mcf_banner, NULL },
{ CLI_PING, cli_func_ping },
{ CLI_SERVER_STATUS, mcf_server_status, NULL },
{ CLI_SERVER_START, mcf_server_startstop, NULL },
......@@ -250,8 +269,6 @@ mgt_cli_vlu(void *priv, const char *p)
return (0);
cli_dispatch(cp->cli, cli_proto, p);
vsb_finish(cp->cli->sb);
AZ(vsb_overflowed(cp->cli->sb));
if (cp->cli->result == CLIS_UNKNOWN) {
/*
* Command not recognized in master, try cacher if it is
......@@ -275,9 +292,9 @@ mgt_cli_vlu(void *priv, const char *p)
cli_out(cp->cli, "%s", q);
free(q);
}
vsb_finish(cp->cli->sb);
AZ(vsb_overflowed(cp->cli->sb));
}
vsb_finish(cp->cli->sb);
AZ(vsb_overflowed(cp->cli->sb));
/* send the result back */
syslog(LOG_INFO, "CLI %d result %d \"%s\"",
......@@ -372,6 +389,9 @@ mgt_cli_setup(int fdi, int fdo, int verbose, const char *ident)
cp->cli->sb = vsb_newauto();
XXXAN(cp->cli->sb);
if (params->cli_banner)
(void)VLU_Data("banner\n", -1, cp->vlu);
cp->ev = calloc(sizeof *cp->ev, 1);
cp->ev->name = cp->name;
cp->ev->fd = fdi;
......
......@@ -757,6 +757,11 @@ static const struct parspec input_parspec[] = {
"Detect and eliminate duplicate purges.\n",
0,
"off", "bool" },
{ "cli_banner", tweak_bool, &master.cli_banner, 0, 0,
"Emit CLI banner on connect.\n"
"Set to off for compatibility with pre 2.1 versions.\n",
0,
"on", "bool" },
{ NULL, NULL, NULL }
};
......
......@@ -225,6 +225,12 @@
"\tCheck status of Varnish cache process.", \
0, 0
#define CLI_BANNER \
"banner", \
"banner", \
"\tPrint welcome banner.", \
0, 0
#define CLI_HIDDEN(foo, min_arg, max_arg) \
foo, NULL, NULL, min_arg, max_arg,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment