[master] 80beeb4 Make it possible for (vmod) functions called from vcl_init{} to set "return(fail)" status, by making the "return(ok)" implicit.

Poul-Henning Kamp phk at FreeBSD.org
Mon Jun 15 09:55:45 CEST 2015


commit 80beeb4104313040bcb19c9e805e8431c4d12ef3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 15 07:54:38 2015 +0000

    Make it possible for (vmod) functions called from vcl_init{} to set
    "return(fail)" status, by making the "return(ok)" implicit.
    
    Notice that setting a fail status does not break off vcl_init{} execution,
    and that the final status is simply the last status set.

diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl
index 3ebe9ce..e4c2a6f 100644
--- a/bin/varnishd/builtin.vcl
+++ b/bin/varnishd/builtin.vcl
@@ -192,7 +192,6 @@ sub vcl_backend_error {
 # Housekeeping
 
 sub vcl_init {
-    return (ok);
 }
 
 sub vcl_fini {
diff --git a/bin/varnishtest/tests/m00022.vtc b/bin/varnishtest/tests/m00022.vtc
index 5febb43..c1d3542 100644
--- a/bin/varnishtest/tests/m00022.vtc
+++ b/bin/varnishtest/tests/m00022.vtc
@@ -1,4 +1,4 @@
-varnishtest "Test std & debug vmod"
+varnishtest "Test vmod failure in vcl_init{}"
 
 server s1 {
 	rxreq
@@ -17,7 +17,6 @@ varnish v1 -errvcl "Planned failure in vcl_init" {
 
 	sub vcl_init {
 		debug.init_fail();
-		return (fail);
 	}
 }
 
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 735341f..e837742 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -700,7 +700,16 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
 		    method_tab[i].name);
 		AZ(VSB_finish(tl->fm[i]));
 		Fc(tl, 1, "{\n");
+		/*
+		 * We want vmods to be able set a FAIL return value
+		 * 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");
 		Fc(tl, 1, "}\n");
 	}
 
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 9e02297..28f37ab 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -33,6 +33,7 @@
 
 #include "cache/cache.h"
 
+#include "vcl.h"
 #include "vrt.h"
 #include "vsb.h"
 #include "vcc_if.h"
@@ -227,6 +228,7 @@ vmod_init_fail(VRT_CTX)
 
 	AN(ctx->msg);
 	VSB_printf(ctx->msg, "Planned failure in vcl_init{}");
+	VRT_handling(ctx, VCL_RET_FAIL);
 }
 
 static void __match_proto__(vmod_priv_free_f)



More information about the varnish-commit mailing list