[master] a1cb651 Fix my brainfart in PRIV_SESS and PRIV_REQ: We want one variable for each VMOD which asks.

Poul-Henning Kamp phk at FreeBSD.org
Thu Oct 2 09:01:37 CEST 2014


commit a1cb65112c717d0de3d6f3bd03da2f07d4dbe6ba
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 2 07:00:53 2014 +0000

    Fix my brainfart in PRIV_SESS and PRIV_REQ:  We want one variable for
    each VMOD which asks.
    
    Patch by:	mithrandir
    Fixes #1600

diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index 0893b4c..4998e74 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -47,26 +47,29 @@ struct vrt_privs {
 	struct vmod_priv		priv[1];
 	const struct VCL_conf		*vcl;
 	uintptr_t			id;
+	uintptr_t			vmod_id;
 };
 
 /*--------------------------------------------------------------------
  */
 
 static struct vmod_priv *
-VRT_priv_dynamic(VRT_CTX, uintptr_t id)
+VRT_priv_dynamic(VRT_CTX, uintptr_t id, uintptr_t vmod_id)
 {
 	struct vrt_privs *vps;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	VTAILQ_FOREACH(vps, &ctx->req->sp->privs, list) {
 		CHECK_OBJ_NOTNULL(vps, VRT_PRIVS_MAGIC);
-		if (vps->vcl == ctx->vcl && vps->id == id)
+		if (vps->vcl == ctx->vcl && vps->id == id
+		    && vps->vmod_id == vmod_id)
 			return (vps->priv);
 	}
 	ALLOC_OBJ(vps, VRT_PRIVS_MAGIC);
 	AN(vps);
 	vps->vcl = ctx->vcl;
 	vps->id = id;
+	vps->vmod_id = vmod_id;
 	VTAILQ_INSERT_TAIL(&ctx->req->sp->privs, vps, list);
 	return (vps->priv);
 }
@@ -91,15 +94,15 @@ VRTPRIV_dynamic_kill(struct sess *sp, uintptr_t id)
 }
 
 struct vmod_priv *
-VRT_priv_req(VRT_CTX)
+VRT_priv_req(VRT_CTX, void *vmod_id)
 {
-	return (VRT_priv_dynamic(ctx, (uintptr_t)ctx->req));
+	return (VRT_priv_dynamic(ctx, (uintptr_t)ctx->req, (uintptr_t)vmod_id));
 }
 
 struct vmod_priv *
-VRT_priv_sess(VRT_CTX)
+VRT_priv_sess(VRT_CTX, void *vmod_id)
 {
-	return (VRT_priv_dynamic(ctx, (uintptr_t)NULL));
+	return (VRT_priv_dynamic(ctx, (uintptr_t)NULL, (uintptr_t)vmod_id));
 }
 
 /*--------------------------------------------------------------------
diff --git a/include/vrt.h b/include/vrt.h
index 92dc040..f9624a6 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -246,8 +246,8 @@ struct vmod_priv {
 typedef int vmod_init_f(struct vmod_priv *,  const struct VCL_conf *);
 
 void VRT_priv_fini(const struct vmod_priv *p);
-struct vmod_priv *VRT_priv_sess(VRT_CTX);
-struct vmod_priv *VRT_priv_req(VRT_CTX);
+struct vmod_priv *VRT_priv_sess(VRT_CTX, void *vmod_id);
+struct vmod_priv *VRT_priv_req(VRT_CTX, void *vmod_id);
 
 /* Stevedore related functions */
 int VRT_Stv(const char *nm);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index acc7b51..32e544c 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -567,10 +567,18 @@ vcc_func(struct vcc *tl, struct expr **e, const char *cfunc,
 			e2 = vcc_mk_expr(VOID, "&%s", buf);
 			p += strlen(p) + 1;
 		} else if (fmt == VOID && !strcmp(p, "PRIV_REQ")) {
-			e2 = vcc_mk_expr(VOID, "VRT_priv_req(ctx)");
+			r = strchr(name, '.');
+			AN(r);
+			e2 = vcc_mk_expr(VOID,
+			    "VRT_priv_req(ctx, &VGC_vmod_%.*s)",
+			    (int) (r - name), name);
 			p += strlen(p) + 1;
 		} else if (fmt == VOID && !strcmp(p, "PRIV_SESS")) {
-			e2 = vcc_mk_expr(VOID, "VRT_priv_sess(ctx)");
+			r = strchr(name, '.');
+			AN(r);
+			e2 = vcc_mk_expr(VOID,
+			    "VRT_priv_sess(ctx, &VGC_vmod_%.*s)",
+			    (int) (r - name), name);
 			p += strlen(p) + 1;
 		} else if (fmt == ENUM) {
 			ExpectErr(tl, ID);



More information about the varnish-commit mailing list