[4.1] 8f465d3 Make std.log() work from vcl_{init,fini}

Lasse Karstensen lkarsten at varnish-software.com
Tue Jun 14 11:46:10 CEST 2016


commit 8f465d363e4ea113ace1d13d302a2f6efbbf0f07
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Mon May 16 18:40:11 2016 +0100

    Make std.log() work from vcl_{init,fini}
    
    Fixes #1924.

diff --git a/bin/varnishtest/tests/r01924.vtc b/bin/varnishtest/tests/r01924.vtc
new file mode 100644
index 0000000..ed5095b
--- /dev/null
+++ b/bin/varnishtest/tests/r01924.vtc
@@ -0,0 +1,22 @@
+varnishtest "Test std.log from vcl_{init,fini}"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	import std;
+
+	sub vcl_init {
+		std.log("init");
+	}
+
+	sub vcl_fini {
+		std.log("fini");
+	}
+} -start
+
+varnish v1 -vcl+backend { }
+
+varnish v1 -cliok "vcl.discard vcl1"
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index c4690b4..c5cdfc1 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -139,17 +139,20 @@ vmod_log(VRT_CTX, const char *fmt, ...)
 	txt t;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	u = WS_Reserve(ctx->ws, 0);
-	t.b = ctx->ws->f;
 	va_start(ap, fmt);
-	t.e = VRT_StringList(ctx->ws->f, u, fmt, ap);
+	if (ctx->vsl != NULL) {
+		u = WS_Reserve(ctx->ws, 0);
+		t.b = ctx->ws->f;
+		t.e = VRT_StringList(ctx->ws->f, u, fmt, ap);
+		if (t.e != NULL) {
+			assert(t.e > t.b);
+			t.e--;
+			VSLbt(ctx->vsl, SLT_VCL_Log, t);
+		}
+		WS_Release(ctx->ws, 0);
+	} else
+		VSLv(SLT_VCL_Log, 0, fmt, ap);
 	va_end(ap);
-	if (t.e != NULL) {
-		assert(t.e > t.b);
-		t.e--;
-		VSLbt(ctx->vsl, SLT_VCL_Log, t);
-	}
-	WS_Release(ctx->ws, 0);
 }
 
 VCL_VOID __match_proto__(td_std_syslog)



More information about the varnish-commit mailing list