Commit 5c279deb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Have the child process use the new "CLI_serve()" functions to

hand cli requests from the master.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4470 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e58db9b9
......@@ -50,13 +50,14 @@ SVNID("$Id$")
#include "cli.h"
#include "cli_priv.h"
#include "cli_common.h"
#include "cli_serve.h"
#include "cache.h"
#include "vlu.h"
#include "vsb.h"
#include "hash_slinger.h"
pthread_t cli_thread;
static struct lock cli_mtx;
static int add_check;
/*
* The CLI commandlist is split in three:
......@@ -77,6 +78,7 @@ CLI_AddFuncs(enum cli_set_e which, struct cli_proto *p)
{
struct cli_proto *c, **cp;
AZ(add_check);
switch (which) {
case MASTER_CLI: cp = &ccf_master_cli; break;
case PUBLIC_CLI: cp = &ccf_public_cli; break;
......@@ -91,86 +93,44 @@ CLI_AddFuncs(enum cli_set_e which, struct cli_proto *p)
Lck_Unlock(&cli_mtx);
}
/*--------------------------------------------------------------------
* Called when we have a full line, look through all three command
* lists to find it.
*/
static int
cli_vlu(void *priv, const char *p)
static void
cli_cb_before(void *priv)
{
struct cli *cli;
int i;
cli = priv;
VSL(SLT_CLI, 0, "Rd %s", p);
VSL(SLT_CLI, 0, "Rd %s", priv);
VCL_Poll();
VBE_Poll();
vsb_clear(cli->sb);
Lck_Lock(&cli_mtx);
cli_dispatch(cli, ccf_master_cli, p);
if (cli->result == CLIS_UNKNOWN) {
vsb_clear(cli->sb);
cli->result = CLIS_OK;
cli_dispatch(cli, ccf_public_cli, p);
}
if (cli->result == CLIS_UNKNOWN) {
vsb_clear(cli->sb);
cli->result = CLIS_OK;
cli_dispatch(cli, ccf_debug_cli, p);
}
Lck_Unlock(&cli_mtx);
vsb_finish(cli->sb);
AZ(vsb_overflowed(cli->sb));
i = cli_writeres(heritage.cli_out, cli);
if (i)
VSL(SLT_Error, 0, "CLI write failed (errno=%d)", errno);
else
VSL(SLT_CLI, 0, "Wr %d %d %s",
i, cli->result, vsb_data(cli->sb));
return (0);
}
/*--------------------------------------------------------------------
* Run CLI on cli pipes from manager
*/
static void
cli_cb_after(void *priv)
{
struct cli *cli;
Lck_Unlock(&cli_mtx);
cli = priv;
VSL(SLT_CLI, 0, "Wr %03u %s", cli->result, vsb_data(cli->sb));
}
void
CLI_Run(void)
{
struct pollfd pfd[1];
struct cli *cli, clis;
struct vlu *vlu;
struct cls *cls;
int i;
cli = &clis;
memset(cli, 0, sizeof *cli);
cli->sb = vsb_newauto();
XXXAN(cli->sb);
vlu = VLU_New(cli, cli_vlu, params->cli_buffer);
XXXAN(vlu);
printf("Ready\n");
while (1) {
pfd[0].fd = heritage.cli_in;
pfd[0].events = POLLIN;
i = poll(pfd, 1, -1);
if (i == -1 && errno == EINTR)
continue;
assert(i == 1);
if (pfd[0].revents & POLLHUP) {
VSL(SLT_CLI, 0, "EOF on CLI connection, worker stops");
break;
}
i = VLU_Fd(heritage.cli_in, vlu);
if (i) {
fprintf(stderr,
"Error on CLI connection, exiting "
"(VLU_Fd %d ev: %x)\n",
i, pfd[0].revents);
break;
}
}
add_check = 1;
cls = CLS_New(cli_cb_before, cli_cb_after, NULL, params->cli_buffer);
AZ(CLS_AddFd(cls, heritage.cli_in, heritage.cli_out, NULL, NULL));
AZ(CLS_AddFunc(cls, ccf_master_cli));
AZ(CLS_AddFunc(cls, ccf_public_cli));
AZ(CLS_AddFunc(cls, ccf_debug_cli));
do {
i = CLS_Poll(cls, -1);
} while(i > 0);
VSL(SLT_CLI, 0, "EOF on CLI connection, worker stops");
}
/*--------------------------------------------------------------------*/
......
......@@ -31,7 +31,7 @@
struct cls;
typedef void cls_cb_f(void *priv);
struct cls *CLS_New(cls_cb_f *before, cls_cb_f *after, void *priv);
struct cls *CLS_New(cls_cb_f *before, cls_cb_f *after, void *priv, unsigned maxlen);
int CLS_AddFd(struct cls *cs, int fdi, int fdo, cls_cb_f *closefunc,
void *priv);
int CLS_AddFunc(struct cls *cs, struct cli_proto *clp);
......
......@@ -78,6 +78,7 @@ struct cls {
VTAILQ_HEAD(,cls_func) funcs;
cls_cb_f *before, *after;
void *priv;
unsigned maxlen;
};
static int
......@@ -92,7 +93,7 @@ cls_vlu(void *priv, const char *p)
CHECK_OBJ_NOTNULL(cs, CLS_MAGIC);
if (cs->before != NULL)
cs->before(cs->priv);
cs->before(cs->priv != NULL ? cs->priv : (void*)(uintptr_t)p);
VTAILQ_FOREACH(cfn, &cs->funcs, list) {
vsb_clear(cfd->cli->sb);
cfd->cli->result = CLIS_OK;
......@@ -100,17 +101,17 @@ cls_vlu(void *priv, const char *p)
if (cfd->cli->result != CLIS_UNKNOWN)
break;
}
if (cs->after != NULL)
cs->after(cs->priv);
vsb_finish(cfd->cli->sb);
AZ(vsb_overflowed(cfd->cli->sb));
if (cs->after != NULL)
cs->after(cs->priv != NULL ? cs->priv : cfd->cli);
if (cli_writeres(cfd->fdo, cfd->cli) || cfd->cli->result == CLIS_CLOSE)
return (1);
return (0);
}
struct cls *
CLS_New(cls_cb_f *before, cls_cb_f *after, void *priv)
CLS_New(cls_cb_f *before, cls_cb_f *after, void *priv, unsigned maxlen)
{
struct cls *cs;
......@@ -121,10 +122,10 @@ CLS_New(cls_cb_f *before, cls_cb_f *after, void *priv)
cs->before = before;
cs->after = after;
cs->priv = priv;
cs->maxlen = maxlen;
return (cs);
}
/* XXX close call back */
int
CLS_AddFd(struct cls *cs, int fdi, int fdo, cls_cb_f *closefunc, void *priv)
{
......@@ -138,7 +139,7 @@ CLS_AddFd(struct cls *cs, int fdi, int fdo, cls_cb_f *closefunc, void *priv)
cfd->cls = cs;
cfd->fdi = fdi;
cfd->fdo = fdo;
cfd->vlu = VLU_New(cfd, cls_vlu, 65536); /* XXX */
cfd->vlu = VLU_New(cfd, cls_vlu, cs->maxlen);
cfd->cli = &cfd->clis;
cfd->cli->sb = vsb_newauto();
cfd->closefunc = closefunc;
......
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