From: phk Date: Fri, 13 Feb 2009 10:13:27 +0000 (+0000) Subject: Add a "banner" command to the CLI interface. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=013c8270f62fb47353881118ad4a341266739f8e;p=varnish 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: svn+ssh://projects.linpro.no/svn/varnish/trunk@3762 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index edeec27e..1c76c485 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -195,6 +195,9 @@ struct params { /* Get rid of duplicate purges */ unsigned purge_dups; + + /* CLI banner */ + unsigned cli_banner; }; extern volatile struct params *params; diff --git a/varnish-cache/bin/varnishd/mgt_child.c b/varnish-cache/bin/varnishd/mgt_child.c index 847c2fa5..12a8a187 100644 --- a/varnish-cache/bin/varnishd/mgt_child.c +++ b/varnish-cache/bin/varnishd/mgt_child.c @@ -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) diff --git a/varnish-cache/bin/varnishd/mgt_cli.c b/varnish-cache/bin/varnishd/mgt_cli.c index 07b5ce48..5f30145b 100644 --- a/varnish-cache/bin/varnishd/mgt_cli.c +++ b/varnish-cache/bin/varnishd/mgt_cli.c @@ -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; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index 9ba5fa11..0de756a0 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -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 } }; diff --git a/varnish-cache/include/cli.h b/varnish-cache/include/cli.h index 6c1602c0..8ff92418 100644 --- a/varnish-cache/include/cli.h +++ b/varnish-cache/include/cli.h @@ -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,