[PATCH 1/3] Implement the init counter hack in vmod_debug

Martin Blix Grydeland martin at varnish-software.com
Wed Feb 25 16:00:13 CET 2015


This allows one time only initialization for vmods
---
 lib/libvmod_debug/vmod_debug.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index b6736fb..7bd719f 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -36,6 +36,8 @@
 #include "vrt.h"
 #include "vcc_if.h"
 
+static int n_init = 0;
+
 VCL_VOID __match_proto__(td_debug_panic)
 vmod_panic(VRT_CTX, const char *str, ...)
 {
@@ -65,13 +67,23 @@ vmod_author(VRT_CTX, VCL_ENUM id)
 	WRONG("Illegal VMOD enum");
 }
 
+static void
+fini_function(void *priv)
+{
+	assert(priv == &n_init);
+
+	assert(n_init > 0);
+	n_init--;
+}
+
 int
 init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
 {
 	(void)cfg;
 
-	priv->priv = strdup("FOO");
-	priv->free = free;
+	priv->priv = &n_init;
+	priv->free = fini_function;
+	n_init++;
 	return (0);
 }
 
@@ -105,7 +117,7 @@ vmod_test_priv_vcl(VRT_CTX, struct vmod_priv *priv)
 {
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	assert(!strcmp(priv->priv, "FOO"));
+	assert(priv->priv == &n_init);
 }
 
 VCL_BLOB
-- 
2.1.4




More information about the varnish-dev mailing list