[master] 085c6a9 Make varnishd -f honor the vcl_path

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jun 26 17:38:06 CEST 2017


commit 085c6a9fc345875b18b853cc274648d2ed34e853
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Jun 8 23:59:51 2017 +0200

    Make varnishd -f honor the vcl_path

diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index e8cd0df..31f9bf7 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -73,6 +73,9 @@ static char		Cn_arg[] = "/tmp/varnishd_C_XXXXXXX";
 static struct vpf_fh *pfh1 = NULL;
 static struct vpf_fh *pfh2 = NULL;
 
+static struct vfil_path *vcl_path = NULL;
+VTAILQ_HEAD(,f_arg) f_args = VTAILQ_HEAD_INITIALIZER(f_args);
+
 int optreset;	// Some has it, some doesn't.  Cheaper than auto*
 
 /*--------------------------------------------------------------------*/
@@ -442,6 +445,27 @@ struct f_arg {
 	VTAILQ_ENTRY(f_arg)	list;
 };
 
+static void
+mgt_f_read(const char *fn)
+{
+	struct f_arg *fa;
+	char *f, *fnp;
+
+	ALLOC_OBJ(fa, F_ARG_MAGIC);
+	AN(fa);
+	REPLACE(fa->farg, fn);
+	VFIL_setpath(&vcl_path, mgt_vcl_path);
+	if (VFIL_searchpath(vcl_path, NULL, &f, fn, &fnp) || f == NULL) {
+		ARGV_ERR("Cannot read -f file '%s' (%s)\n",
+		    fnp != NULL ? fnp : fn, strerror(errno));
+		free(fnp);
+	}
+	free(fa->farg);
+	fa->farg = fnp;
+	fa->src = f;
+	VTAILQ_INSERT_TAIL(&f_args, fa, list);
+}
+
 static const char opt_spec[] = "a:b:Cdf:Fh:i:I:j:l:M:n:P:p:r:S:s:T:t:VW:x:";
 
 int
@@ -473,7 +497,6 @@ main(int argc, char * const *argv)
 	struct vev *e;
 	struct f_arg *fa;
 	struct vsb *vsb;
-	VTAILQ_HEAD(,f_arg) f_args = VTAILQ_HEAD_INITIALIZER(f_args);
 	pid_t pid;
 
 	setbuf(stdout, NULL);
@@ -626,14 +649,7 @@ main(int argc, char * const *argv)
 				novcl = 1;
 				break;
 			}
-			ALLOC_OBJ(fa, F_ARG_MAGIC);
-			AN(fa);
-			REPLACE(fa->farg, optarg);
-			fa->src = VFIL_readfile(NULL, fa->farg, NULL);
-			if (fa->src == NULL)
-				ARGV_ERR("Cannot read -f file (%s): %s\n",
-				    fa->farg, strerror(errno));
-			VTAILQ_INSERT_TAIL(&f_args, fa, list);
+			mgt_f_read(optarg);
 			break;
 		case 'h':
 			h_arg = optarg;
diff --git a/bin/varnishtest/tests/r02342.vtc b/bin/varnishtest/tests/r02342.vtc
new file mode 100644
index 0000000..bb37b6a
--- /dev/null
+++ b/bin/varnishtest/tests/r02342.vtc
@@ -0,0 +1,20 @@
+varnishtest "honor vcl_path with varnishd -f"
+
+shell {
+	cat >unlikely_file_name.vcl <<-EOF
+	vcl 4.0;
+
+	backend be {
+		.host = "${bad_backend}";
+	}
+	EOF
+}
+
+shell -err -expect "Cannot read -f file 'unlikely_file_name.vcl'" {
+	varnishd -F -a :0 -n ${tmpdir}/tmp -f unlikely_file_name.vcl
+}
+
+varnish v1 -arg "-p vcl_path=${tmpdir} -f unlikely_file_name.vcl" -start
+
+# Even when loaded from a relative path, show an absolute one
+varnish v1 -cliexpect "VCL.SHOW .+ ${tmpdir}/unlikely_file_name.vcl" "vcl.show -v boot"



More information about the varnish-commit mailing list