r4994 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Wed Jun 30 14:55:57 CEST 2010


Author: phk
Date: 2010-06-30 14:55:57 +0200 (Wed, 30 Jun 2010)
New Revision: 4994

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
   trunk/varnish-cache/include/libvarnish.h
   trunk/varnish-cache/lib/libvarnish/vtmpfile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
Log:
Make vcl_dir work for vcl.load and include filenames.



Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-06-29 12:29:00 UTC (rev 4993)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-06-30 12:55:57 UTC (rev 4994)
@@ -153,6 +153,7 @@
 	vp = priv;
 	sb = vsb_newauto();
 	XXXAN(sb);
+	VCC_VCL_dir(vcc, mgt_vcl_dir);
 	csrc = VCC_Compile(vcc, sb, vp->vcl);
 	vsb_finish(sb);
 	AZ(vsb_overflowed(sb));
@@ -212,7 +213,7 @@
 	}
 
 	if (C_flag) {
-		csrc = vreadfile(sf);
+		csrc = vreadfile(NULL, sf);
 		XXXAN(csrc);
 		(void)fputs(csrc, stdout);
 		free(csrc);
@@ -513,7 +514,7 @@
 		return;
 	}
 
-	vcl = vreadfile(av[3]);
+	vcl = vreadfile(mgt_vcl_dir, av[3]);
 	if (vcl == NULL) {
 		cli_out(cli, "Cannot open '%s'", av[3]);
 		cli_result(cli, CLIS_PARAM);

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2010-06-29 12:29:00 UTC (rev 4993)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2010-06-30 12:55:57 UTC (rev 4994)
@@ -541,7 +541,7 @@
 	}
 
 	if (f_arg != NULL) {
-		vcl = vreadfile(f_arg);
+		vcl = vreadfile(NULL, f_arg);
 		if (vcl == NULL) {
 			fprintf(stderr, "Cannot read '%s': %s\n",
 			    f_arg, strerror(errno));

Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h	2010-06-29 12:29:00 UTC (rev 4993)
+++ trunk/varnish-cache/include/libvarnish.h	2010-06-30 12:55:57 UTC (rev 4994)
@@ -97,7 +97,7 @@
 
 /* from libvarnish/vtmpfile.c */
 int vtmpfile(char *);
-char *vreadfile(const char *fn);
+char *vreadfile(const char *pfx, const char *fn);
 
 const char* svn_version(void);
 

Modified: trunk/varnish-cache/lib/libvarnish/vtmpfile.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/vtmpfile.c	2010-06-29 12:29:00 UTC (rev 4993)
+++ trunk/varnish-cache/lib/libvarnish/vtmpfile.c	2010-06-30 12:55:57 UTC (rev 4994)
@@ -34,6 +34,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -98,12 +99,19 @@
 }
 
 char *
-vreadfile(const char *fn)
+vreadfile(const char *pfx, const char *fn)
 {
 	int fd, err;
 	char *r;
+	char fnb[PATH_MAX + 1];
 
-	fd = open(fn, O_RDONLY);
+	if (fn[0] == '/')
+		fd = open(fn, O_RDONLY);
+	else if (pfx != NULL) {
+		bprintf(fnb, "/%s/%s", pfx, fn); /* XXX: graceful length check */
+		fd = open(fnb, O_RDONLY);
+	} else 
+		fd = open(fn, O_RDONLY);
 	if (fd < 0)
 		return (NULL);
 	r = vreadfd(fd);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-06-29 12:29:00 UTC (rev 4993)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-06-30 12:55:57 UTC (rev 4994)
@@ -382,12 +382,12 @@
 /*--------------------------------------------------------------------*/
 
 static struct source *
-vcc_file_source(struct vsb *sb, const char *fn)
+vcc_file_source(struct vcc *tl, struct vsb *sb, const char *fn)
 {
 	char *f;
 	struct source *sp;
 
-	f = vreadfile(fn);
+	f = vreadfile(tl->vcl_dir, fn);
 	if (f == NULL) {
 		vsb_printf(sb, "Cannot read file '%s': %s\n",
 		    fn, strerror(errno));
@@ -428,7 +428,7 @@
 		}
 		assert(t2 != NULL);
 
-		sp = vcc_file_source(tl->sb, t1->dec);
+		sp = vcc_file_source(tl, tl->sb, t1->dec);
 		if (sp == NULL) {
 			vcc_ErrWhere(tl, t1);
 			return;




More information about the varnish-commit mailing list