[master] 3740956 Make std.syslog() work from vcl_{init,fini}

Federico G. Schwindt fgsch at lodoss.net
Mon May 16 21:40:09 CEST 2016


commit 37409564590a9ccac69fc595a118beeacd2676ae
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Mon May 16 20:38:09 2016 +0100

    Make std.syslog() work from vcl_{init,fini}
    
    Related to #1924.

diff --git a/bin/varnishtest/tests/r01924.vtc b/bin/varnishtest/tests/r01924.vtc
index ed5095b..d553124 100644
--- a/bin/varnishtest/tests/r01924.vtc
+++ b/bin/varnishtest/tests/r01924.vtc
@@ -1,4 +1,4 @@
-varnishtest "Test std.log from vcl_{init,fini}"
+varnishtest "Test std.{log,syslog} from vcl_{init,fini}"
 
 server s1 {
 	rxreq
@@ -10,10 +10,12 @@ varnish v1 -vcl+backend {
 
 	sub vcl_init {
 		std.log("init");
+		std.syslog(8 + 7, "init");
 	}
 
 	sub vcl_fini {
 		std.log("fini");
+		std.syslog(8 + 7, "fini");
 	}
 } -start
 
diff --git a/configure.ac b/configure.ac
index ceddc8f..ad83ab7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -243,6 +243,7 @@ AC_CHECK_FUNCS([nanosleep])
 AC_CHECK_FUNCS([setppriv])
 AC_CHECK_FUNCS([fallocate])
 AC_CHECK_FUNCS([closefrom])
+AC_CHECK_FUNCS([vsyslog])
 
 save_LIBS="${LIBS}"
 LIBS="${PTHREAD_LIBS}"
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 4522147..ed66405 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -163,14 +163,17 @@ vmod_syslog(VRT_CTX, VCL_INT fac, 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->ws != 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)
+			syslog((int)fac, "%s", t.b);
+		WS_Release(ctx->ws, 0);
+	} else
+		vsyslog((int)fac, fmt, ap);
 	va_end(ap);
-	if (t.e != NULL)
-		syslog((int)fac, "%s", t.b);
-	WS_Release(ctx->ws, 0);
 }
 
 VCL_VOID __match_proto__(td_std_collect)



More information about the varnish-commit mailing list