Commit 2e7ad94b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

(Re)Implement passthru of cli commands, we can now talk with the

cache process again.


git-svn-id: http://www.varnish-cache.org/svn/trunk@629 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 52c5fe01
......@@ -20,6 +20,7 @@
#include "mgt.h"
static int cli_i = -1, cli_o = -1;
static pthread_mutex_t cli_mtx;
/*--------------------------------------------------------------------*/
......@@ -35,6 +36,69 @@ mcf_server_startstop(struct cli *cli, char **av, void *priv)
mgt_start_child();
}
/*--------------------------------------------------------------------
* Passthru of cli commands.
*/
static void
mcf_passthru(struct cli *cli, char **av, void *priv)
{
char buf[BUFSIZ], *bp, *be;
char *p;
unsigned u, v;
int i, j, k;
AZ(pthread_mutex_lock(&cli_mtx));
/* Request */
if (cli_o <= 0) {
AZ(pthread_mutex_unlock(&cli_mtx));
cli_result(cli, CLIS_CANT);
cli_out(cli, "Cache process not running");
return;
}
(void)priv;
bp = buf;
be = bp + sizeof buf;
for (u = 1; av[u] != NULL; u++) {
v = strlen(av[u]);
if (5 + bp + 4 * v > be) {
*bp = '\0';
v = bp - buf;
i = write(cli_o, buf, v);
assert(i == v);
bp = buf;
}
*bp++ = '"';
for (p = av[u]; *p; p++) {
switch (*p) {
case '\\': *bp++ = '\\'; *bp++ = '\\'; break;
case '\n': *bp++ = '\\'; *bp++ = 'n'; break;
case '"': *bp++ = '\\'; *bp++ = '"'; break;
default: *bp++ = *p; break;
}
}
*bp++ = '"';
*bp++ = ' ';
}
if (bp != buf) {
*bp++ = '\n';
v = bp - buf;
i = write(cli_o, buf, v);
assert(i == v);
}
/* Response */
i = read(cli_i, buf, sizeof buf - 1);
assert(i > 0);
buf[i] = '\0';
j = sscanf(buf, "%u %u\n%n", &u, &v, &k);
assert(j == 2);
assert(i == k + v + 1);
cli_result(cli, u);
cli_out(cli, "%*.*s", v, v, buf + k);
AZ(pthread_mutex_unlock(&cli_mtx));
}
/*--------------------------------------------------------------------*/
static struct cli_proto *cli_proto;
......@@ -70,6 +134,7 @@ mgt_cli_init(void)
unsigned u, v;
AZ(pthread_mutex_init(&cli_mtx, NULL));
/*
* Build the joint cli_proto by combining the manager process
* entries with with the cache process entries. The latter
......@@ -93,7 +158,7 @@ mgt_cli_init(void)
if (v < u)
continue;
cli_proto[u] = *cp;
cli_proto[u].func = NULL; /* XXX: pass */
cli_proto[u].func = mcf_passthru;
u++;
}
......
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