r4472 - in trunk/varnish-cache: bin/varnishd lib/libvarnish
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jan 18 22:53:58 CET 2010
Author: phk
Date: 2010-01-18 22:53:58 +0100 (Mon, 18 Jan 2010)
New Revision: 4472
Modified:
trunk/varnish-cache/bin/varnishd/mgt_cli.c
trunk/varnish-cache/lib/libvarnish/cli.c
Log:
Add a wild-card CLI hack, and use it for passing cli to the child
process.
Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-01-18 21:28:19 UTC (rev 4471)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-01-18 21:53:58 UTC (rev 4472)
@@ -203,6 +203,47 @@
{ NULL }
};
+/*--------------------------------------------------------------------*/
+
+static void
+mcf_askchild(struct cli *cli, const char * const *av, void *priv)
+{
+ int i;
+ char *q;
+ unsigned u;
+
+ (void)av;
+ (void)priv;
+ /*
+ * Command not recognized in master, try cacher if it is
+ * running.
+ */
+ if (cli_o <= 0) {
+ cli_result(cli, CLIS_UNKNOWN);
+ cli_out(cli,
+ "Unknown request in manager process "
+ "(child not running).\n"
+ "Type 'help' for more info.");
+ return;
+ }
+ AN(cli->cmd);
+ i = write(cli_o, cli->cmd, strlen(cli->cmd));
+ xxxassert(i == strlen(cli->cmd));
+ i = write(cli_o, "\n", 1);
+ xxxassert(i == 1);
+ (void)cli_readres(cli_i,
+ &u, &q, params->cli_timeout);
+ cli_result(cli, u);
+ cli_out(cli, "%s", q);
+ free(q);
+}
+
+static struct cli_proto cli_askchild[] = {
+ { "*", "<wild-card-entry>", "\t<fall through to cacher>\n",
+ 0, 9999, mcf_askchild, NULL},
+ { NULL }
+};
+
/*--------------------------------------------------------------------
* Ask the child something over CLI, return zero only if everything is
* happy happy.
@@ -359,9 +400,6 @@
mgt_cli_vlu(void *priv, const char *p)
{
struct cli_port *cp;
- char *q;
- unsigned u;
- int i;
CAST_OBJ_NOTNULL(cp, priv, CLI_PORT_MAGIC);
vsb_clear(cp->cli->sb);
@@ -374,6 +412,7 @@
if (*p == '\0')
return (0);
+ cp->cli->cmd = p;
if (secret_file != NULL && cp->challenge[0] != '\0') {
/* Authentication not yet passed */
cli_dispatch(cp->cli, cli_auth, p);
@@ -381,37 +420,20 @@
mgt_cli_challenge(cp);
} else {
cli_dispatch(cp->cli, cli_proto, p);
- if (cp->cli->result == CLIS_UNKNOWN)
+ if (cp->cli->result == CLIS_UNKNOWN) {
+ vsb_clear(cp->cli->sb);
cli_dispatch(cp->cli, cli_debug, p);
+ }
if (cp->cli->result == CLIS_UNKNOWN) {
- /*
- * Command not recognized in master, try cacher if it is
- * running.
- */
vsb_clear(cp->cli->sb);
- cp->cli->result = CLIS_OK;
- if (cli_o <= 0) {
- cli_result(cp->cli, CLIS_UNKNOWN);
- cli_out(cp->cli,
- "Unknown request in manager process "
- "(child not running).\n"
- "Type 'help' for more info.");
- } else {
- i = write(cli_o, p, strlen(p));
- xxxassert(i == strlen(p));
- i = write(cli_o, "\n", 1);
- xxxassert(i == 1);
- (void)cli_readres(cli_i,
- &u, &q, params->cli_timeout);
- cli_result(cp->cli, u);
- cli_out(cp->cli, "%s", q);
- free(q);
- }
+ cli_dispatch(cp->cli, cli_askchild, p);
}
}
vsb_finish(cp->cli->sb);
AZ(vsb_overflowed(cp->cli->sb));
+ cp->cli->cmd = NULL;
+
/* send the result back */
syslog(LOG_INFO, "CLI %d result %d \"%s\"",
cp->fdi, cp->cli->result, p);
Modified: trunk/varnish-cache/lib/libvarnish/cli.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/cli.c 2010-01-18 21:28:19 UTC (rev 4471)
+++ trunk/varnish-cache/lib/libvarnish/cli.c 2010-01-18 21:53:58 UTC (rev 4472)
@@ -97,9 +97,12 @@
cli_result(cli, CLIS_UNKNOWN);
break;
}
- for (cp = clp; cp->request != NULL; cp++)
+ for (cp = clp; cp->request != NULL; cp++) {
if (!strcmp(av[1], cp->request))
break;
+ if (!strcmp("*", cp->request))
+ break;
+ }
if (cp->request == NULL) {
cli_out(cli,
"Unknown request.\nType 'help' for more info.\n");
More information about the varnish-commit
mailing list