[master] 21c215f Always initialize ctx->handling to zero, and try to avoid setting it more than once.

Poul-Henning Kamp phk at FreeBSD.org
Thu Feb 2 11:38:04 CET 2017


commit 21c215fac90827731b822859198acea84d39ca7c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Feb 2 10:36:37 2017 +0000

    Always initialize ctx->handling to zero, and try to avoid setting
    it more than once.

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index ba7f296..1ddfb0c 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -107,6 +107,7 @@ vcl_get_ctx(unsigned method, int msg)
 {
 	AZ(ctx_cli.handling);
 	INIT_OBJ(&ctx_cli, VRT_CTX_MAGIC);
+	handling_cli = 0;
 	ctx_cli.handling = &handling_cli;
 	ctx_cli.method = method;
 	if (msg) {
@@ -148,6 +149,7 @@ vcl_send_event(VRT_CTX, enum vcl_event_e ev)
 	       ev == VCL_EVENT_COLD ||
 	       ev == VCL_EVENT_DISCARD);
 	AN(ctx->handling);
+	*ctx->handling = 0;
 	AN(ctx->ws);
 
 	if (ev == VCL_EVENT_LOAD || ev == VCL_EVENT_WARM)
@@ -713,6 +715,7 @@ vcl_cancel_load(VRT_CTX, struct cli *cli, const char *name, const char *step)
 	VCLI_Out(cli, "VCL \"%s\" Failed %s", name, step);
 	if (VSB_len(ctx->msg))
 		VCLI_Out(cli, "\nMessage:\n\t%s", VSB_data(ctx->msg));
+	*ctx->handling = 0;
 	AZ(vcl->conf->event_vcl(ctx, VCL_EVENT_DISCARD));
 	vcl_KillBackends(vcl);
 	VCL_Close(&vcl);
@@ -753,6 +756,7 @@ vcl_load(struct cli *cli, struct vrt_ctx *ctx,
 		vcl_cancel_load(ctx, cli, name, "initialization");
 		return;
 	}
+	assert(*ctx->handling == VCL_RET_OK);
 	VSB_clear(ctx->msg);
 	i = vcl_set_state(ctx, state);
 	if (i) {
@@ -761,7 +765,6 @@ vcl_load(struct cli *cli, struct vrt_ctx *ctx,
 		return;
 	}
 	bprintf(vcl->state, "%s", state + 1);
-	assert(*ctx->handling == VCL_RET_OK);
 	VCLI_Out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
 	VTAILQ_INSERT_TAIL(&vcl_head, vcl, list);
 	Lck_Lock(&vcl_mtx);
@@ -1041,9 +1044,9 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 	ctx.vsl = vsl;
 	ctx.specific = specific;
 	ctx.method = method;
+	wrk->handling = 0;
 	ctx.handling = &wrk->handling;
 	aws = WS_Snapshot(wrk->aws);
-	wrk->handling = 0;
 	wrk->cur_method = method;
 	wrk->seen_methods |= method;
 	AN(vsl);
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 1abf5b7..55d759f 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -252,7 +252,9 @@ VRT_handling(VRT_CTX, unsigned hand)
 {
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	assert(hand > 0);
 	assert(hand < VCL_RET_MAX);
+	// XXX:NOTYET assert(*ctx->handling == 0);
 	*ctx->handling = hand;
 }
 
diff --git a/bin/varnishtest/tests/b00014.vtc b/bin/varnishtest/tests/b00014.vtc
index a6f08f3..eb75dfb 100644
--- a/bin/varnishtest/tests/b00014.vtc
+++ b/bin/varnishtest/tests/b00014.vtc
@@ -1,6 +1,5 @@
 varnishtest "Check -f command line arg"
 
-
 server s1 {
 	rxreq
 	expect req.url == "/foo"
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index a7dc484..9de5eac 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -311,6 +311,8 @@ EmitInitFini(const struct vcc *tl)
 	}
 
 	Fc(tl, 0, "\t(void)VGC_function_vcl_init(ctx);\n");
+	Fc(tl, 0, "\tif (*ctx->handling == 0)\n");
+	Fc(tl, 0, "\t\tVRT_handling(ctx, VCL_RET_OK);\n");
 	Fc(tl, 0, "\treturn (*ctx->handling == VCL_RET_OK ? 0: -1);\n");
 	Fc(tl, 0, "}\n");
 
@@ -655,8 +657,6 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 		 * in members called from vcl_init, so set OK up front
 		 * and return with whatever was set last.
 		 */
-		if (method_tab[i].bitval == VCL_MET_INIT)
-			Fc(tl, 1, "  VRT_handling(ctx, VCL_RET_OK);\n");
 		Fc(tl, 1, "%s", VSB_data(tl->fm[i]));
 		if (method_tab[i].bitval == VCL_MET_INIT)
 			Fc(tl, 1, "  return (1);\n");



More information about the varnish-commit mailing list