]> err.no Git - varnish/commitdiff
Add a "banner" command to the CLI interface.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 13 Feb 2009 10:13:27 +0000 (10:13 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 13 Feb 2009 10:13:27 +0000 (10:13 +0000)
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

varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt_child.c
varnish-cache/bin/varnishd/mgt_cli.c
varnish-cache/bin/varnishd/mgt_param.c
varnish-cache/include/cli.h

index edeec27ee82d2bbbf8d96771bf61500539775d66..1c76c485e9997e69f6cc226611e10ecb0a8d67c5 100644 (file)
@@ -195,6 +195,9 @@ struct params {
 
        /* Get rid of duplicate purges */
        unsigned                purge_dups;
+
+       /* CLI banner */
+       unsigned                cli_banner;
 };
 
 extern volatile struct params *params;
index 847c2fa5b8a5d2480e6d3b17aa1ce5529d18bc00..12a8a1878264ca1cf20dcfbae12806ad25494a55 100644 (file)
@@ -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)
index 07b5ce48a8dd536ede7c5a7457a1e1aaf08889f0..5f30145bbc680dea1f72190f3f4ab891e60a4ef2 100644 (file)
@@ -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;
index 9ba5fa1179790a21d095c956ec75ce92a5e8d79d..0de756a0690e1d90786af049df04e0b44fa25543 100644 (file)
@@ -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 }
 };
 
index 6c1602c07c3897d19fe4a05b1424fe88780dcf1d..8ff924183cdc40204e485f295cfd1eed38868a1b 100644 (file)
        "\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,