[master] 8e7b0f01d add a vsl to the cli ctx if there is no msg buffer

Nils Goroll nils.goroll at uplex.de
Wed Nov 6 14:47:07 UTC 2019


commit 8e7b0f01d7c2bb0ae57c016f8bfb01d1fbd00dcb
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed May 15 13:30:39 2019 +0200

    add a vsl to the cli ctx if there is no msg buffer
    
    This is another requirement for use of VRT_fail() in director context.
    
    For code checking for (struct vrt_ctx *)->vsl the logging order now may
    change, and we might want to review our VSL() calls if the ctx vsl
    buffer may now be used instead.
    
    Ref #2997

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 2a26c34a3..8131260c9 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -68,6 +68,7 @@ static struct vrt_ctx ctx_cli;
 static unsigned handling_cli;
 static struct ws ws_cli;
 static uintptr_t ws_snapshot_cli;
+static struct vsl_log vsl_cli;
 
 /*--------------------------------------------------------------------*/
 
@@ -127,6 +128,8 @@ VCL_Get_CliCtx(int msg)
 	if (msg) {
 		ctx_cli.msg = VSB_new_auto();
 		AN(ctx_cli.msg);
+	} else {
+		ctx_cli.vsl = &vsl_cli;
 	}
 	ctx_cli.ws = &ws_cli;
 	WS_Assert(ctx_cli.ws);
@@ -142,6 +145,8 @@ VCL_Rel_CliCtx(struct vrt_ctx **ctx)
 	AN((*ctx)->handling);
 	if (ctx_cli.msg)
 		VSB_destroy(&ctx_cli.msg);
+	if (ctx_cli.vsl)
+		VSL_Flush(ctx_cli.vsl, 0);
 	WS_Assert(ctx_cli.ws);
 	WS_Reset(&ws_cli, ws_snapshot_cli);
 	INIT_OBJ(*ctx, VRT_CTX_MAGIC);
@@ -915,6 +920,8 @@ static struct cli_proto vcl_cmds[] = {
 void
 VCL_Init(void)
 {
+	unsigned sz;
+	char *vslbuf;
 
 	assert(cache_param->workspace_client > 0);
 	WS_Init(&ws_cli, "cli", malloc(cache_param->workspace_client),
@@ -922,4 +929,8 @@ VCL_Init(void)
 	ws_snapshot_cli = WS_Snapshot(&ws_cli);
 	CLI_AddFuncs(vcl_cmds);
 	Lck_New(&vcl_mtx, lck_vcl);
+	sz = cache_param->vsl_buffer;
+	vslbuf = malloc(sz);
+	AN(vslbuf);
+	VSL_Setup(&vsl_cli, vslbuf, sz);
 }
diff --git a/bin/varnishtest/tests/v00041.vtc b/bin/varnishtest/tests/v00041.vtc
index 7d14b388f..ce162378e 100644
--- a/bin/varnishtest/tests/v00041.vtc
+++ b/bin/varnishtest/tests/v00041.vtc
@@ -106,15 +106,18 @@ logexpect l1 -v v1 -g raw -d 1 {
 	expect 0 =    BereqHeader	{^bx0: b /snafu}
 	expect 0 =    VCL_Log		^bar
 
+	# this is not the order of events because std.log logs
+	# into the CLI ctx->vsl, while vmod_debug VSL() goes straight
+	# to the log.
 	expect * 0    Debug		{^vcl1: VCL_EVENT_COLD}
 	expect * 0    CLI		{^Rd vcl.discard}
 	expect 0 =    Debug		{^test_priv_task.*new.$}
 	expect 0 =    Debug		{^test_priv_task.*update.$}
 	expect 0 =    Debug		{^test_priv_task.*exists.$}
-	expect * =    VCL_Log		{^func cleaning up}
 	expect 0 =    Debug		{^test_priv_task.*exists.$}
-	expect 0 =    VCL_Log		{^obj cleaning up}
 	expect 0 =    Debug		{^priv_task_free}
+	expect * =    VCL_Log		{^func cleaning up}
+	expect 0 =    VCL_Log		{^obj cleaning up}
 } -start
 
 client c1 {


More information about the varnish-commit mailing list