Commit 4aeb4f63 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Simplify the mgt->child handover of CLI setup

parent d0eb0f15
......@@ -44,7 +44,7 @@
pthread_t cli_thread;
static struct lock cli_mtx;
static int add_check;
static struct VCLS *cls;
static struct VCLS *cache_cls;
/*
* The CLI commandlist is split in three:
......@@ -64,7 +64,7 @@ CLI_AddFuncs(struct cli_proto *p)
AZ(add_check);
Lck_Lock(&cli_mtx);
VCLS_AddFunc(cls, 0, p);
VCLS_AddFunc(cache_cls, 0, p);
Lck_Unlock(&cli_mtx);
}
......@@ -96,10 +96,10 @@ CLI_Run(void)
add_check = 1;
AN(VCLS_AddFd(cls, heritage.cli_in, heritage.cli_out, NULL, NULL));
AN(VCLS_AddFd(cache_cls, heritage.cli_in, heritage.cli_out, NULL, NULL));
do {
i = VCLS_PollFd(cls, heritage.cli_in, -1);
i = VCLS_PollFd(cache_cls, heritage.cli_in, -1);
} while (i == 0);
VSL(SLT_CLI, 0, "EOF on CLI connection, worker stops");
}
......@@ -123,10 +123,9 @@ CLI_Init(void)
Lck_New(&cli_mtx, lck_cli);
cli_thread = pthread_self();
cls = VCLS_New(cli_cb_before, cli_cb_after,
&cache_param->cli_buffer, &cache_param->cli_limit);
AN(cls);
VCLS_Clone(cls, heritage.cls);
cache_cls = heritage.cls;
AN(cache_cls);
VCLS_SetHooks(cache_cls, cli_cb_before, cli_cb_after);
CLI_AddFuncs(cli_cmds);
}
......@@ -364,9 +364,9 @@ void
mgt_cli_init_cls(void)
{
mgt_cls = VCLS_New(mgt_cli_cb_before, mgt_cli_cb_after,
&mgt_param.cli_buffer, &mgt_param.cli_limit);
mgt_cls = VCLS_New(&mgt_param.cli_buffer, &mgt_param.cli_limit);
AN(mgt_cls);
VCLS_SetHooks(mgt_cls, mgt_cli_cb_before, mgt_cli_cb_after);
VCLS_AddFunc(mgt_cls, MCF_NOAUTH, cli_auth);
VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_proto);
VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_debug);
......
......@@ -92,14 +92,13 @@ void VCLI_SetResult(struct cli *cli, unsigned r);
typedef void cls_cb_f(void *priv);
typedef void cls_cbc_f(const struct cli*);
struct VCLS *VCLS_New(cls_cbc_f *before, cls_cbc_f *after,
volatile unsigned *maxlen, volatile unsigned *limit);
struct VCLS *VCLS_New(volatile unsigned *maxlen, volatile unsigned *limit);
void VCLS_SetHooks(struct VCLS *, cls_cbc_f *, cls_cbc_f *);
struct cli *VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc,
void *priv);
void VCLS_AddFunc(struct VCLS *cs, unsigned auth, struct cli_proto *clp);
int VCLS_PollFd(struct VCLS *cs, int fd, int timeout);
void VCLS_Destroy(struct VCLS **);
void VCLS_Clone(struct VCLS *cs, struct VCLS *cso);
/* From libvarnish/cli.c */
cli_func_t VCLS_func_close;
......
......@@ -400,8 +400,7 @@ cls_vlu(void *priv, const char *p)
}
struct VCLS *
VCLS_New(cls_cbc_f *before, cls_cbc_f *after, volatile unsigned *maxlen,
volatile unsigned *limit)
VCLS_New(volatile unsigned *maxlen, volatile unsigned *limit)
{
struct VCLS *cs;
......@@ -409,13 +408,20 @@ VCLS_New(cls_cbc_f *before, cls_cbc_f *after, volatile unsigned *maxlen,
AN(cs);
VTAILQ_INIT(&cs->fds);
VTAILQ_INIT(&cs->funcs);
cs->before = before;
cs->after = after;
cs->maxlen = maxlen;
cs->limit = limit;
return (cs);
}
void
VCLS_SetHooks(struct VCLS *cs, cls_cbc_f *before, cls_cbc_f *after)
{
CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
cs->before = before;
cs->after = after;
}
struct cli *
VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc, void *priv)
{
......@@ -499,26 +505,6 @@ VCLS_AddFunc(struct VCLS *cs, unsigned auth, struct cli_proto *clp)
}
}
/*
* This function has *very* special semantics, related to the mgt/worker
* process Copy-On-Write memory relationship.
*/
void
VCLS_Clone(struct VCLS *cs, struct VCLS *cso)
{
struct cli_proto *clp, *clp2;
CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
CHECK_OBJ_NOTNULL(cso, VCLS_MAGIC);
VTAILQ_FOREACH_SAFE(clp, &cso->funcs, list, clp2) {
VTAILQ_REMOVE(&cso->funcs, clp, list);
VTAILQ_INSERT_TAIL(&cs->funcs, clp, list);
clp->auth = 0;
clp->func = NULL;
}
}
int
VCLS_PollFd(struct VCLS *cs, int fd, int timeout)
{
......
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