[4.1] 87e0e7b Pass either vclsrc or vclfilename to the VCC compiler, and eliminate the VCL fileopening logic in mgt so we have it only one place.

Lasse Karstensen lkarsten at varnish-software.com
Thu Jan 14 15:15:12 CET 2016


commit 87e0e7b45d304daccec1da317cb64f1b3f8117ab
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 8 21:35:13 2016 +0000

    Pass either vclsrc or vclfilename to the VCC compiler, and eliminate
    the VCL fileopening logic in mgt so we have it only one place.

diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 5fb12d4..a31bc6a 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -161,7 +161,7 @@ void STV_Config_Transient(void);
 
 /* mgt_vcc.c */
 char *mgt_VccCompile(struct cli *, const char *vclname, const char *vclsrc,
-    int C_flag);
+    const char *vclsrcfile, int C_flag);
 void mgt_vcc_init(void);
 
 void mgt_vcl_init(void);
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index c7a641b..77f67c0 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -52,7 +52,8 @@ struct vcc_priv {
 	unsigned	magic;
 #define VCC_PRIV_MAGIC	0x70080cb8
 	char		*dir;
-	const char	*src;
+	const char	*vclsrc;
+	const char	*vclsrcfile;
 	char		*csrcfile;
 	char		*libfile;
 };
@@ -99,7 +100,7 @@ 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);
-	csrc = VCC_Compile(vcp, sb, vp->src);
+	csrc = VCC_Compile(vcp, sb, vp->vclsrc, vp->vclsrcfile);
 	AZ(VSB_finish(sb));
 	if (VSB_len(sb))
 		printf("%s", VSB_data(sb));
@@ -251,7 +252,7 @@ mgt_vcc_compile(struct vcc_priv *vp, struct vsb *sb, int C_flag)
 
 char *
 mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc,
-    int C_flag)
+    const char *vclsrcfile, int C_flag)
 {
 	struct vcc_priv vp;
 	struct vsb *sb;
@@ -263,7 +264,8 @@ mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc,
 	XXXAN(sb);
 
 	INIT_OBJ(&vp, VCC_PRIV_MAGIC);
-	vp.src = vclsrc;
+	vp.vclsrc = vclsrc;
+	vp.vclsrcfile = vclsrcfile;
 
 	VSB_printf(sb, "vcl_%s", vclname);
 	AZ(VSB_finish(sb));
@@ -271,7 +273,6 @@ mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc,
 	AN(vp.dir);
 	VJ_make_vcldir(vp.dir);
 
-
 	VSB_clear(sb);
 	VSB_printf(sb, "%s/%s", vp.dir, VGC_SRC);
 	AZ(VSB_finish(sb));
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index ae2f898..0b24c65 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -43,7 +43,6 @@
 #include "vcli.h"
 #include "vcli_priv.h"
 #include "vev.h"
-#include "vfil.h"
 #include "vtim.h"
 
 #include "mgt_cli.h"
@@ -60,7 +59,6 @@ struct vclprog {
 static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead);
 static struct vclprog		*active_vcl;
 static struct vev *e_poker;
-static struct vfil_path *vcl_path;
 
 /*--------------------------------------------------------------------*/
 
@@ -160,7 +158,7 @@ mgt_vcl_setstate(struct vclprog *vp, int warm)
 
 static void
 mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
-    const char *state, int C_flag)
+    const char *vclsrcfile, const char *state, int C_flag)
 {
 	unsigned status;
 	char *lib, *p;
@@ -178,7 +176,7 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
 		return;
 	}
 
-	lib = mgt_VccCompile(cli, vclname, vclsrc, C_flag);
+	lib = mgt_VccCompile(cli, vclname, vclsrc, vclsrcfile, C_flag);
 	if (lib == NULL)
 		return;
 
@@ -210,7 +208,7 @@ mgt_vcc_default(struct cli *cli, const char *b_arg, const char *vclsrc,
 
 	if (b_arg == NULL) {
 		AN(vclsrc);
-		mgt_new_vcl(cli, "boot", vclsrc, NULL, C_flag);
+		mgt_new_vcl(cli, "boot", vclsrc, NULL, NULL, C_flag);
 		return;
 	}
 
@@ -220,7 +218,7 @@ mgt_vcc_default(struct cli *cli, const char *b_arg, const char *vclsrc,
 	    "backend default {\n"
 	    "    .host = \"%s\";\n"
 	    "}\n", b_arg);
-	mgt_new_vcl(cli, "boot", buf, NULL, C_flag);
+	mgt_new_vcl(cli, "boot", buf, NULL, NULL, C_flag);
 }
 
 /*--------------------------------------------------------------------*/
@@ -264,13 +262,12 @@ mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv)
 		return;
 	}
 
-	mgt_new_vcl(cli, av[2], av[3], av[4], 0);
+	mgt_new_vcl(cli, av[2], av[3], NULL, av[4], 0);
 }
 
 void
 mcf_vcl_load(struct cli *cli, const char * const *av, void *priv)
 {
-	char *vcl, *fn;
 	struct vclprog *vp;
 
 	(void)priv;
@@ -281,17 +278,7 @@ mcf_vcl_load(struct cli *cli, const char * const *av, void *priv)
 		return;
 	}
 
-	VFIL_setpath(&vcl_path, mgt_vcl_dir);
-	if (VFIL_searchpath(vcl_path, NULL, &vcl, av[3], &fn)) {
-		VCLI_Out(cli, "Cannot open '%s'", fn != NULL ? fn : av[3]);
-		REPLACE(fn, NULL);
-		VCLI_SetResult(cli, CLIS_PARAM);
-		return;
-	}
-	REPLACE(fn, NULL);
-
-	mgt_new_vcl(cli, av[2], vcl, av[4], 0);
-	free(vcl);
+	mgt_new_vcl(cli, av[2], NULL, av[3], av[4], 0);
 }
 
 static struct vclprog *
diff --git a/bin/varnishtest/tests/c00053.vtc b/bin/varnishtest/tests/c00053.vtc
index 9b87fa1..6a34045 100644
--- a/bin/varnishtest/tests/c00053.vtc
+++ b/bin/varnishtest/tests/c00053.vtc
@@ -13,7 +13,7 @@ varnish v1 -vcl+backend {
 
 varnish v1 -cliok "param.set vcc_unsafe_path off"
 
-varnish v1 -errvcl {Include path is unsafe} {
+varnish v1 -errvcl {' is unsafe} {
 	backend default {
 		.host = "${s1_sock}";
 	}
diff --git a/include/libvcc.h b/include/libvcc.h
index 696123e..fbd7bd1 100644
--- a/include/libvcc.h
+++ b/include/libvcc.h
@@ -38,4 +38,5 @@ 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);
 
-char *VCC_Compile(const struct vcp *, struct vsb *sb, const char *b);
+char *VCC_Compile(const struct vcp *, struct vsb *sb,
+    const char *vclsrc, const char *vclsrcfile);
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index f35e07b..95eab85 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -456,7 +456,7 @@ vcc_file_source(const struct vcp * const vcp, struct vsb *sb, const char *fn)
 	struct source *sp;
 
 	if (!vcp->unsafe_path && strchr(fn, '/') != NULL) {
-		VSB_printf(sb, "Include path is unsafe '%s'\n", fn);
+		VSB_printf(sb, "VCL filename '%s' is unsafe.\n", fn);
 		return (NULL);
 	}
 	f = NULL;
@@ -753,12 +753,19 @@ vcc_CompileSource(const struct vcp * const vcp, struct vsb *sb,
  */
 
 char *
-VCC_Compile(const struct vcp *vcp, struct vsb *sb, const char *b)
+VCC_Compile(const struct vcp *vcp, struct vsb *sb,
+    const char *vclsrc, const char *vclsrcfile)
 {
 	struct source *sp;
 	char *r;
 
-	sp = vcc_new_source(b, NULL, "input");
+	if (vclsrc != NULL) {
+		AZ(vclsrcfile);
+		sp = vcc_new_source(vclsrc, NULL, "input");
+	} else {
+		AN(vclsrcfile);
+		sp = vcc_file_source(vcp, sb, vclsrcfile);
+	}
 	if (sp == NULL)
 		return (NULL);
 	r = vcc_CompileSource(vcp, sb, sp);



More information about the varnish-commit mailing list