[master] a31bed0 Tell VCC about our stevedores, and define symbols for them.

Poul-Henning Kamp phk at FreeBSD.org
Thu May 19 10:00:09 CEST 2016


commit a31bed0236f96ef8d38df1f43dcd0fee2628c808
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed May 18 22:50:59 2016 +0000

    Tell VCC about our stevedores, and define symbols for them.

diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 8847c03..d35ccd4 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -41,6 +41,7 @@
 #include <sys/stat.h>
 
 #include "mgt/mgt.h"
+#include "storage/storage.h"
 
 #include "libvcc.h"
 #include "vcli.h"
@@ -87,6 +88,7 @@ run_vcc(void *priv)
 	struct vcc_priv *vp;
 	int fd, i, l;
 	struct vcp *vcp;
+	struct stevedore *stv;
 
 	VJ_subproc(JAIL_SUBPROC_VCC);
 	CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC);
@@ -103,6 +105,9 @@ run_vcc(void *priv)
 	VCP_Err_Unref(vcp, mgt_vcc_err_unref);
 	VCP_Allow_InlineC(vcp, mgt_vcc_allow_inline_c);
 	VCP_Unsafe_Path(vcp, mgt_vcc_unsafe_path);
+	VTAILQ_FOREACH(stv, &stv_stevedores, list)
+		VCP_Stevedore(vcp, stv->ident);
+	VCP_Stevedore(vcp, stv_transient->ident);
 	csrc = VCC_Compile(vcp, sb, vp->vclsrc, vp->vclsrcfile);
 	AZ(VSB_finish(sb));
 	if (VSB_len(sb))
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 2ce76dd..da7ece4 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -231,6 +231,17 @@ VRT_Stv(const char *nm)
 	return (0);
 }
 
+struct stevedore *
+VRT_stevedore(const char *nm)
+{
+	struct stevedore *stv;
+
+	VTAILQ_FOREACH(stv, &stv_stevedores, list)
+		if (!strcmp(stv->ident, nm))
+			return (stv);
+	WRONG("Unknown stevedore name");
+}
+
 #define VRTSTVVAR(nm, vtype, ctype, dval)	\
 ctype						\
 VRT_Stv_##nm(const char *nm)			\
diff --git a/include/libvcc.h b/include/libvcc.h
index 0d3bb53..1ae4b8a 100644
--- a/include/libvcc.h
+++ b/include/libvcc.h
@@ -28,15 +28,16 @@
  *
  */
 
-struct vcc;
+struct vcp;
 
 struct vcp *VCP_New(void);
-void VCP_Builtin_VCL(struct vcp *, const char *str);
-void VCP_VCL_path(struct vcp *, const char *str);
-void VCP_VMOD_path(struct vcp *, const char *str);
-void VCP_Err_Unref(struct vcp *tl, unsigned u);
-void VCP_Allow_InlineC(struct vcp *tl, unsigned u);
-void VCP_Unsafe_Path(struct vcp *tl, unsigned u);
+void VCP_Allow_InlineC(struct vcp *, unsigned);
+void VCP_Builtin_VCL(struct vcp *, const char *);
+void VCP_Err_Unref(struct vcp *, unsigned);
+void VCP_Stevedore(struct vcp *, const char *);
+void VCP_Unsafe_Path(struct vcp *, unsigned);
+void VCP_VCL_path(struct vcp *, const char *);
+void VCP_VMOD_path(struct vcp *, const char *);
 
-char *VCC_Compile(const struct vcp *, struct vsb *sb,
+char *VCC_Compile(const struct vcp *, struct vsb *,
     const char *vclsrc, const char *vclsrcfile);
diff --git a/include/tbl/symbol_kind.h b/include/tbl/symbol_kind.h
index 497f400..e9add4a 100644
--- a/include/tbl/symbol_kind.h
+++ b/include/tbl/symbol_kind.h
@@ -29,14 +29,15 @@
 
 /*lint -save -e525 -e539 */
 VCC_SYMB(NONE,		none)
-VCC_SYMB(VAR,		var)
-VCC_SYMB(FUNC,		func)		/* VMOD function/procedure */
-VCC_SYMB(VMOD,		vmod)
 VCC_SYMB(ACL,		acl)
-VCC_SYMB(SUB,		sub)		/* VCL subroutine */
 VCC_SYMB(BACKEND,	backend)
+VCC_SYMB(FUNC,		func)		/* VMOD function/procedure */
+VCC_SYMB(METHOD,	method)
+VCC_SYMB(OBJECT,	object)
 VCC_SYMB(PROBE,		probe)
+VCC_SYMB(STEVEDORE,	stevedore)
+VCC_SYMB(SUB,		sub)		/* VCL subroutine */
+VCC_SYMB(VAR,		var)
+VCC_SYMB(VMOD,		vmod)
 VCC_SYMB(WILDCARD,	wildcard)
-VCC_SYMB(OBJECT,	object)
-VCC_SYMB(METHOD,	method)
 /*lint -restore */
diff --git a/include/vrt.h b/include/vrt.h
index 9963460..bcaa2cd 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -65,6 +65,7 @@ struct busyobj;
 struct director;
 struct http;
 struct req;
+struct stevedore;
 struct suckaddr;
 struct vcl;
 struct vmod;
@@ -91,6 +92,7 @@ typedef long					VCL_INT;
 typedef const struct suckaddr *			VCL_IP;
 typedef const struct vrt_backend_probe *	VCL_PROBE;
 typedef double					VCL_REAL;
+typedef struct stevedore *			VCL_STEVEDORE;
 typedef const char *				VCL_STRING;
 typedef double					VCL_TIME;
 typedef void					VCL_VOID;
@@ -330,6 +332,7 @@ struct vmod_priv *VRT_priv_top(VRT_CTX, void *vmod_id);
 
 /* Stevedore related functions */
 int VRT_Stv(const char *nm);
+struct stevedore *VRT_stevedore(const char *nm);
 
 /* Convert things to string */
 
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 0ee166d..a9657e6 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -680,7 +680,7 @@ vcc_CompileSource(const struct vcp * const vcp, struct vsb *sb,
     struct source *sp)
 {
 	struct vcc *tl;
-	struct symbol *sym;
+	struct symbol *sym, *sym2;
 	const struct var *v;
 	struct vsb *vsb;
 
@@ -692,6 +692,16 @@ vcc_CompileSource(const struct vcp * const vcp, struct vsb *sb,
 
 	vcc_Expr_Init(tl);
 
+	VTAILQ_FOREACH(sym, &vcp->symbols, list) {
+		assert(sym->eval == vcc_Eval_Generic);
+		sym2 = VCC_AddSymbolStr(tl, sym->name, sym->kind);
+		sym2->fmt = sym->fmt;
+		sym2->eval = sym->eval;
+		sym2->eval_priv = sym->eval_priv;
+		sym2->ndef = 1;
+		sym2->nref = 1;
+	}
+
 	for (v = tl->vars; v->name != NULL; v++) {
 		if (v->fmt == HEADER) {
 			sym = VCC_AddSymbolStr(tl, v->name, SYM_WILDCARD);
@@ -860,6 +870,7 @@ VCP_New(void)
 
 	ALLOC_OBJ(vcp, VCP_MAGIC);
 	AN(vcp);
+	VTAILQ_INIT(&vcp->symbols);
 
 	return (vcp);
 }
@@ -927,3 +938,19 @@ VCP_Unsafe_Path(struct vcp *vcp, unsigned u)
 	CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
 	vcp->unsafe_path = u;
 }
+
+void
+VCP_Stevedore(struct vcp *vcp, const char *stv_name)
+{
+	struct symbol *sym;
+
+	CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
+	ALLOC_OBJ(sym, SYMBOL_MAGIC);
+	AN(sym);
+	REPLACE(sym->name, stv_name);		/* XXX storage.* ? */
+	sym->kind = SYM_STEVEDORE;
+	VCC_GenericSymbol(NULL, sym, STEVEDORE,
+	    "VRT_stevedore(\"%s\")", stv_name);
+	VTAILQ_INSERT_TAIL(&vcp->symbols, sym, list);
+}
+
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index d20059b..6d6b7da 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -165,6 +165,8 @@ struct vcp {
 	unsigned		err_unref;
 	unsigned		allow_inline_c;
 	unsigned		unsafe_path;
+
+	VTAILQ_HEAD(,symbol)	symbols;
 };
 
 struct vcc {
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index e65acd1..d043d21 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -824,6 +824,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
 		case ACL:	kind = SYM_ACL; break;
 		case BACKEND:	kind = SYM_BACKEND; break;
 		case PROBE:	kind = SYM_PROBE; break;
+		case STEVEDORE:	kind = SYM_STEVEDORE; break;
 		default:	kind = SYM_NONE; break;
 		}
 		if (kind != SYM_NONE)
@@ -853,6 +854,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
 		case SYM_FUNC:
 		case SYM_ACL:
 		case SYM_BACKEND:
+		case SYM_STEVEDORE:
 		case SYM_PROBE:
 			AN(sym->eval);
 			AZ(*e);
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 22b6db9..02e9fe0 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -154,7 +154,11 @@ VCC_GenericSymbol(struct vcc *tl, struct symbol *sym,
 	VSB_vprintf(vsb, str, ap);
 	va_end(ap);
 	AZ(VSB_finish(vsb));
-	sym->eval_priv = TlDup(tl, VSB_data(vsb));
+	if (tl != NULL)
+		sym->eval_priv = TlDup(tl, VSB_data(vsb));
+	else
+		sym->eval_priv = strdup(VSB_data(vsb));
+	AN(sym->eval_priv);
 	sym->eval = vcc_Eval_Generic;
 	sym->fmt = fmt;
 	VSB_destroy(&vsb);



More information about the varnish-commit mailing list