[PATCH 4/5] Add a VRT_cliout function

Martin Blix Grydeland martin at varnish-software.com
Wed Jun 10 11:06:01 CEST 2015


The VRT_cliout function enables VRT users to output diagnostics
strings to the CLI interface.

This is mostly useful from vmod init functions, where the output would
become visible for the user during vcl.load.

If there is no CLI context available, the messages are sent to stdout.
---
 bin/varnishd/cache/cache_vrt.c | 14 ++++++++++++++
 include/vcli_priv.h            |  1 +
 include/vrt.h                  |  2 ++
 lib/libvarnish/cli_common.c    |  9 ++++++++-
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 9b4aaff..e930f72 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -31,6 +31,8 @@
 
 #include "config.h"
 
+#include <stdarg.h>
+
 #include "cache.h"
 
 #include "cache_director.h"
@@ -41,6 +43,7 @@
 #include "vrt_obj.h"
 #include "vtcp.h"
 #include "vtim.h"
+#include "vcli_priv.h"
 
 const void * const vrt_magic_string_end = &vrt_magic_string_end;
 const void * const vrt_magic_string_unset = &vrt_magic_string_unset;
@@ -524,3 +527,14 @@ VRT_memmove(void *dst, const void *src, unsigned len)
 
 	(void)memmove(dst, src, len);
 }
+
+void
+VRT_cliout(VRT_CTX, const char *fmt, ...)
+{
+	va_list ap;
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	va_start(ap, fmt);
+	VCLI_Out_VA(ctx->cli, fmt, ap);
+	va_end(ap);
+}
diff --git a/include/vcli_priv.h b/include/vcli_priv.h
index 2f98d7d..c71f66f 100644
--- a/include/vcli_priv.h
+++ b/include/vcli_priv.h
@@ -55,5 +55,6 @@ struct cli_proto {
 int VCLI_Overflow(struct cli *cli);
 void VCLI_Out(struct cli *cli, const char *fmt, ...)
     __v_printflike(2, 3);
+void VCLI_Out_VA(struct cli *cli, const char *fmt, va_list ap);
 void VCLI_Quote(struct cli *cli, const char *str);
 void VCLI_SetResult(struct cli *cli, unsigned r);
diff --git a/include/vrt.h b/include/vrt.h
index 499eaac..7e04062 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -239,6 +239,8 @@ void VRT_memmove(void *dst, const void *src, unsigned len);
 
 void VRT_Rollback(VRT_CTX, const struct http *);
 
+void VRT_cliout(VRT_CTX, const char *fmt, ...);
+
 /* Synthetic pages */
 void VRT_synth_page(VRT_CTX, const char *, ...);
 
diff --git a/lib/libvarnish/cli_common.c b/lib/libvarnish/cli_common.c
index 44a6869..7ccd6a0 100644
--- a/lib/libvarnish/cli_common.c
+++ b/lib/libvarnish/cli_common.c
@@ -59,6 +59,14 @@ VCLI_Out(struct cli *cli, const char *fmt, ...)
 	va_list ap;
 
 	va_start(ap, fmt);
+	VCLI_Out_VA(cli, fmt, ap);
+	va_end(ap);
+}
+
+void
+VCLI_Out_VA(struct cli *cli, const char *fmt, va_list ap)
+{
+
 	if (cli != NULL) {
 		CHECK_OBJ_NOTNULL(cli, CLI_MAGIC);
 		if (VSB_len(cli->sb) < *cli->limit)
@@ -68,7 +76,6 @@ VCLI_Out(struct cli *cli, const char *fmt, ...)
 	} else {
 		(void)vfprintf(stdout, fmt, ap);
 	}
-	va_end(ap);
 }
 
 /*lint -e{818} cli could be const */
-- 
2.1.4




More information about the varnish-dev mailing list