[master] 3eff253 Replace the separate init/fini functions for the compiled VCL with a single "event" function which takes the event as parameter.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Dec 10 15:18:57 CET 2014
commit 3eff253ecc2591b7441cf90cbdb8164fc290aa96
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Dec 10 13:13:37 2014 +0000
Replace the separate init/fini functions for the compiled VCL
with a single "event" function which takes the event as parameter.
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 713abe6..d0fc13e 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -217,9 +217,9 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
ctx.handling = &hand;
ctx.cli = cli;
- if (vcl->conf->init_vcl(&ctx)) {
+ if (vcl->conf->event_vcl(&ctx, VCL_EVENT_INIT)) {
VCLI_Out(cli, "VCL \"%s\" Failed to initialize", name);
- vcl->conf->fini_vcl(&ctx);
+ AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI));
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
return (1);
@@ -229,7 +229,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
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);
+ AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI));
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
return (1);
@@ -268,7 +268,7 @@ VCL_Nuke(struct vcls *vcl)
ctx.handling = &hand;
(void)vcl->conf->fini_func(&ctx);
assert(hand == VCL_RET_OK);
- vcl->conf->fini_vcl(&ctx);
+ AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI));
free(vcl->name);
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index cf6bd66..e582c0f 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -945,6 +945,12 @@ struct ws;
struct cli;
struct worker;
+enum vcl_event_e {
+ VCL_EVENT_INIT,
+ VCL_EVENT_FINI,
+};
+
+typedef int vcl_event_f(VRT_CTX, enum vcl_event_e);
typedef int vcl_init_f(VRT_CTX);
typedef void vcl_fini_f(VRT_CTX);
typedef int vcl_func_f(VRT_CTX);
@@ -992,8 +998,7 @@ struct VCL_conf {
const char **srcname;
const char **srcbody;
- vcl_init_f *init_vcl;
- vcl_fini_f *fini_vcl;
+ vcl_event_f *event_vcl;
""")
for i in returns:
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 237a07c..9aabb59 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -362,10 +362,21 @@ EmitStruct(const struct vcc *tl)
Fc(tl, 0, "\nstatic struct director\t*directors[%d];\n",
tl->ndirector);
+ Fc(tl, 0, "\nstatic int\n");
+ Fc(tl, 0, "VGC_Event(VRT_CTX, enum vcl_event_e ev)\n");
+ Fc(tl, 0, "{\n");
+ Fc(tl, 0, "\tif (ev == VCL_EVENT_INIT)\n");
+ Fc(tl, 0, "\t\treturn(VGC_Init(ctx));\n");
+ Fc(tl, 0, "\telse if (ev == VCL_EVENT_FINI) {\n");
+ Fc(tl, 0, "\t\tVGC_Fini(ctx);\n");
+ Fc(tl, 0, "\t\treturn(0);\n");
+ Fc(tl, 0, "\t} else\n");
+ Fc(tl, 0, "\t\treturn (-1);\n");
+ Fc(tl, 0, "}\n");
+
Fc(tl, 0, "\nconst struct VCL_conf VCL_conf = {\n");
Fc(tl, 0, "\t.magic = VCL_CONF_MAGIC,\n");
- Fc(tl, 0, "\t.init_vcl = VGC_Init,\n");
- Fc(tl, 0, "\t.fini_vcl = VGC_Fini,\n");
+ Fc(tl, 0, "\t.event_vcl = VGC_Event,\n");
Fc(tl, 0, "\t.ndirector = %d,\n", tl->ndirector);
Fc(tl, 0, "\t.director = directors,\n");
Fc(tl, 0, "\t.ref = VGC_ref,\n");
More information about the varnish-commit
mailing list