[master] ebfcb92 Introduce VRT_fail() which fails VCL processing with a single-line message which either goes into CLI (vcl_init{}) or VSL (all others).

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 7 11:14:06 CET 2017


commit ebfcb92b8d3054967fbf3c615e0c37153057b654
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 7 10:11:55 2017 +0000

    Introduce VRT_fail() which fails VCL processing with a single-line
    message which either goes into CLI (vcl_init{}) or VSL (all others).

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 55d759f..d865891 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -258,6 +258,26 @@ VRT_handling(VRT_CTX, unsigned hand)
 	*ctx->handling = hand;
 }
 
+/*--------------------------------------------------------------------*/
+
+void
+VRT_fail(VRT_CTX, const char *fmt, ...)
+{
+	va_list ap;
+
+	assert(ctx->vsl != NULL || ctx->msg != NULL);
+	AZ(strchr(fmt, '\n'));
+	va_start(ap, fmt);
+	if (ctx->vsl != NULL)
+		VSLbv(ctx->vsl, SLT_VCL_Error, fmt, ap);
+	else {
+		VSB_vprintf(ctx->msg, fmt, ap);
+		VSB_putc(ctx->msg, '\n');
+	}
+	va_end(ap);
+	VRT_handling(ctx, VCL_RET_FAIL);
+}
+
 /*--------------------------------------------------------------------
  * Feed data into the hash calculation
  */
diff --git a/bin/varnishtest/tests/v00051.vtc b/bin/varnishtest/tests/v00051.vtc
index 56eee1e..664af71 100644
--- a/bin/varnishtest/tests/v00051.vtc
+++ b/bin/varnishtest/tests/v00051.vtc
@@ -26,7 +26,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1001	VCL_call	"RECV"
-	expect 0 1001	Debug		"Forced failure"
+	expect 0 1001	VCL_Error	"Forced failure"
 	expect 0 1001	VCL_return	"fail"
 } -start
 
@@ -47,7 +47,7 @@ logexpect l1 -wait
 
 logexpect l1 -v v1 -g raw {
 	expect * 1003	VCL_call	"RECV"
-	expect 0 1003	Debug		"Forced failure"
+	expect 0 1003	VCL_Error	"Forced failure"
 	expect 0 1003	VCL_return	"fail"
 	expect * 1003	VCL_call	"SYNTH"
 	expect 0 1003	VCL_return	"restart"
@@ -86,7 +86,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1007	VCL_call	"SYNTH"
-	expect * 1007	Debug		"Forced failure"
+	expect * 1007	VCL_Error	"Forced failure"
 	expect 0 1007	VCL_return	"fail"
 } -start
 
@@ -115,7 +115,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1009	VCL_call	"HASH"
-	expect 0 1009	Debug		"Forced failure"
+	expect 0 1009	VCL_Error	"Forced failure"
 	expect 0 1009	VCL_return	"fail"
 } -start
 
@@ -150,7 +150,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1012	VCL_call	"PIPE"
-	expect 0 1012	Debug		"Forced failure"
+	expect 0 1012	VCL_Error	"Forced failure"
 	expect 0 1012	VCL_return	"fail"
 } -start
 
@@ -184,7 +184,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1014	VCL_call	"PASS"
-	expect 0 1014	Debug		"Forced failure"
+	expect 0 1014	VCL_Error	"Forced failure"
 	expect 0 1014	VCL_return	"fail"
 } -start
 
@@ -218,7 +218,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1016	VCL_call	"PURGE"
-	expect 0 1016	Debug		"Forced failure"
+	expect 0 1016	VCL_Error	"Forced failure"
 	expect 0 1016	VCL_return	"fail"
 } -start
 
@@ -249,7 +249,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1018	VCL_call	"MISS"
-	expect 0 1018	Debug		"Forced failure"
+	expect 0 1018	VCL_Error	"Forced failure"
 	expect 0 1018	VCL_return	"fail"
 } -start
 
@@ -280,7 +280,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1020	VCL_call	"HIT"
-	expect 0 1020	Debug		"Forced failure"
+	expect 0 1020	VCL_Error	"Forced failure"
 	expect 0 1020	VCL_return	"fail"
 } -start
 
@@ -311,7 +311,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1022	VCL_call	"DELIVER"
-	expect 0 1022	Debug		"Forced failure"
+	expect 0 1022	VCL_Error	"Forced failure"
 	expect 0 1022	VCL_return	"fail"
 } -start
 
@@ -340,7 +340,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1025	VCL_call	"BACKEND_FETCH"
-	expect 0 1025	Debug		"Forced failure"
+	expect 0 1025	VCL_Error	"Forced failure"
 	expect 0 1025	VCL_return	"fail"
 } -start
 
@@ -374,7 +374,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1028	VCL_call	"BACKEND_ERROR"
-	expect 0 1028	Debug		"Forced failure"
+	expect 0 1028	VCL_Error	"Forced failure"
 	expect 0 1028	VCL_return	"fail"
 } -start
 
@@ -409,7 +409,7 @@ varnish v1 -vcl+backend {
 
 logexpect l1 -v v1 -g raw {
 	expect * 1031	VCL_call	"BACKEND_RESPONSE"
-	expect 0 1031	Debug		"Forced failure"
+	expect 0 1031	VCL_Error	"Forced failure"
 	expect 0 1031	VCL_return	"fail"
 } -start
 
diff --git a/include/vrt.h b/include/vrt.h
index b6915d7..d3aee0b 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -293,6 +293,7 @@ struct http *VRT_selecthttp(VRT_CTX, enum gethdr_e);
 const char *VRT_GetHdr(VRT_CTX, const struct gethdr_s *);
 void VRT_SetHdr(VRT_CTX, const struct gethdr_s *, const char *, ...);
 void VRT_handling(VRT_CTX, unsigned hand);
+void VRT_fail(VRT_CTX, const char *fmt, ...) __v_printflike(2,3);
 
 void VRT_hashdata(VRT_CTX, const char *str, ...);
 
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 8e857fd..8cae9f3 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -256,11 +256,7 @@ VCL_VOID __match_proto__()
 vmod_fail(VRT_CTX)
 {
 
-	if(ctx->msg != NULL)
-		VSB_printf(ctx->msg, "Forced failure");
-	else if (ctx->vsl != NULL)
-		VSLb(ctx->vsl, SLT_Debug, "Forced failure");
-	VRT_handling(ctx, VCL_RET_FAIL);
+	VRT_fail(ctx, "Forced failure");
 }
 
 static void __match_proto__(vmod_priv_free_f)



More information about the varnish-commit mailing list