Commit 04c40433 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use vrt_ctx also for init/fini

parent 6c29a9c8
......@@ -517,12 +517,12 @@ vdi_simple_finish(const struct director *d, struct worker *wrk,
/*--------------------------------------------------------------------*/
void
VRT_fini_dir(struct cli *cli, struct director *d)
VRT_fini_dir(const struct vrt_ctx *ctx, struct director *d)
{
struct vdi_simple *vs;
(void)cli;
ASSERT_CLI();
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
......@@ -534,13 +534,14 @@ VRT_fini_dir(struct cli *cli, struct director *d)
}
void
VRT_init_dir(struct cli *cli, struct director **bp, int idx, const void *priv)
VRT_init_dir(const struct vrt_ctx *ctx, struct director **bp, int idx,
const void *priv)
{
const struct vrt_backend *t;
struct vdi_simple *vs;
ASSERT_CLI();
(void)cli;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
t = priv;
ALLOC_OBJ(vs, VDI_SIMPLE_MAGIC);
......@@ -557,7 +558,7 @@ VRT_init_dir(struct cli *cli, struct director **bp, int idx, const void *priv)
vs->vrt = t;
vs->backend = VBE_AddBackend(cli, t);
vs->backend = VBE_AddBackend(NULL, t);
if (vs->vrt->probe != NULL)
VBP_Insert(vs->backend, vs->vrt->probe, vs->vrt->hosthdr);
......
......@@ -180,9 +180,6 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
ASSERT_CLI();
memset(&ctx, 0, sizeof ctx);
ctx.magic = VRT_CTX_MAGIC;
vcl = vcl_find(name);
if (vcl != NULL) {
VCLI_Out(cli, "Config '%s' already loaded", name);
......@@ -214,17 +211,26 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
FREE_OBJ(vcl);
return (1);
}
if (vcl->conf->init_vcl(cli)) {
memset(&ctx, 0, sizeof ctx);
ctx.magic = VRT_CTX_MAGIC;
ctx.method = VCL_MET_INIT;
ctx.handling = &hand;
ctx.cli = cli;
if (vcl->conf->init_vcl(&ctx)) {
VCLI_Out(cli, "VCL \"%s\" Failed to initialize", name);
vcl->conf->fini_vcl(&ctx);
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
return (1);
}
ctx.method = VCL_MET_INIT;
ctx.handling = &hand;
(void)vcl->conf->init_func(&ctx);
if (hand == VCL_RET_FAIL) {
VCLI_Out(cli, "VCL \"%s\" vcl_init{} failed", name);
ctx.method = VCL_MET_FINI;
(void)vcl->conf->fini_func(&ctx);
vcl->conf->fini_vcl(&ctx);
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
return (1);
......@@ -264,7 +270,7 @@ VCL_Nuke(struct vcls *vcl)
ctx.handling = &hand;
(void)vcl->conf->fini_func(&ctx);
assert(hand == VCL_RET_OK);
vcl->conf->fini_vcl(NULL);
vcl->conf->fini_vcl(&ctx);
free(vcl->name);
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
......
......@@ -63,7 +63,7 @@ static VTAILQ_HEAD(,vmod) vmods = VTAILQ_HEAD_INITIALIZER(vmods);
int
VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
const char *path, const char *file_id, struct cli *cli)
const char *path, const char *file_id, const struct vrt_ctx *ctx)
{
struct vmod *v;
const struct vmod_data *d;
......@@ -71,12 +71,14 @@ VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
void *dlhdl;
ASSERT_CLI();
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(ctx->cli);
dlhdl = dlopen(path, RTLD_NOW | RTLD_LOCAL);
if (dlhdl == NULL) {
VCLI_Out(cli, "Loading VMOD %s from %s:\n", nm, path);
VCLI_Out(cli, "dlopen() failed: %s\n", dlerror());
VCLI_Out(cli, "Check child process permissions.\n");
VCLI_Out(ctx->cli, "Loading VMOD %s from %s:\n", nm, path);
VCLI_Out(ctx->cli, "dlopen() failed: %s\n", dlerror());
VCLI_Out(ctx->cli, "Check child process permissions.\n");
return (1);
}
......@@ -94,8 +96,9 @@ VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
if (d == NULL ||
d->file_id == NULL ||
strcmp(d->file_id, file_id)) {
VCLI_Out(cli, "Loading VMOD %s from %s:\n", nm, path);
VCLI_Out(cli,
VCLI_Out(ctx->cli,
"Loading VMOD %s from %s:\n", nm, path);
VCLI_Out(ctx->cli,
"This is no longer the same file seen by"
" the VCL-compiler.\n");
(void)dlclose(v->hdl);
......@@ -111,8 +114,9 @@ VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
d->proto == NULL ||
d->spec == NULL ||
d->abi == NULL) {
VCLI_Out(cli, "Loading VMOD %s from %s:\n", nm, path);
VCLI_Out(cli, "VMOD data is mangled.\n");
VCLI_Out(ctx->cli,
"Loading VMOD %s from %s:\n", nm, path);
VCLI_Out(ctx->cli, "VMOD data is mangled.\n");
(void)dlclose(v->hdl);
FREE_OBJ(v);
return (1);
......
......@@ -89,6 +89,7 @@ struct vrt_ctx {
unsigned method;
unsigned *handling;
struct cli *cli; // Only in ...init()
struct vsl_log *vsl;
struct VCL_conf *vcl;
struct ws *ws;
......@@ -223,15 +224,16 @@ void VRT_Rollback(const struct vrt_ctx *, const struct http *);
void VRT_synth_page(const struct vrt_ctx *, const char *, ...);
/* Backend related */
void VRT_init_dir(struct cli *, struct director **, int idx, const void *priv);
void VRT_fini_dir(struct cli *, struct director *);
void VRT_init_dir(const struct vrt_ctx*, struct director **, int idx,
const void *priv);
void VRT_fini_dir(const struct vrt_ctx*, struct director *);
/* Suckaddr related */
int VRT_VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst);
/* VMOD/Modules related */
int VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
const char *path, const char *file_id, struct cli *cli);
const char *path, const char *file_id, const struct vrt_ctx *ctx);
void VRT_Vmod_Fini(void **hdl);
struct vmod_priv;
......
......@@ -929,8 +929,8 @@ struct ws;
struct cli;
struct worker;
typedef int vcl_init_f(struct cli *);
typedef void vcl_fini_f(struct cli *);
typedef int vcl_init_f(const struct vrt_ctx *ctx);
typedef void vcl_fini_f(const struct vrt_ctx *ctx);
typedef int vcl_func_f(const struct vrt_ctx *ctx);
""")
......
......@@ -423,9 +423,9 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be)
ifp = New_IniFin(tl);
VSB_printf(ifp->ini,
"\tVRT_init_dir(cli, VCL_conf.director,\n"
"\tVRT_init_dir(ctx, VCL_conf.director,\n"
"\t VGC_backend_%s, &vgc_dir_priv_%s);", vgcname, vgcname);
VSB_printf(ifp->fin, "\tVRT_fini_dir(cli, VGCDIR(%s));", vgcname);
VSB_printf(ifp->fin, "\tVRT_fini_dir(ctx, VGCDIR(%s));", vgcname);
tl->ndirector++;
}
......
......@@ -302,7 +302,7 @@ EmitInitFunc(const struct vcc *tl)
{
struct inifin *p;
Fc(tl, 0, "\nstatic int\nVGC_Init(struct cli *cli)\n{\n\n");
Fc(tl, 0, "\nstatic int\nVGC_Init(const struct vrt_ctx *ctx)\n{\n\n");
VTAILQ_FOREACH(p, &tl->inifin, list) {
AZ(VSB_finish(p->ini));
if (VSB_len(p->ini))
......@@ -319,7 +319,7 @@ EmitFiniFunc(const struct vcc *tl)
{
struct inifin *p;
Fc(tl, 0, "\nstatic void\nVGC_Fini(struct cli *cli)\n{\n\n");
Fc(tl, 0, "\nstatic void\nVGC_Fini(const struct vrt_ctx *ctx)\n{\n\n");
VTAILQ_FOREACH_REVERSE(p, &tl->inifin, inifinhead, list) {
AZ(VSB_finish(p->fin));
......
......@@ -177,7 +177,7 @@ vcc_ParseImport(struct vcc *tl)
AN(vmd);
AN(vmd->file_id);
VSB_printf(ifp->ini, "\t \"%s\",\n", vmd->file_id);
VSB_printf(ifp->ini, "\t cli))\n");
VSB_printf(ifp->ini, "\t ctx))\n");
VSB_printf(ifp->ini, "\t\treturn(1);");
/* XXX: zero the function pointer structure ?*/
......
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