[master] 900702b Move each vcl into a subdirectory under the -n directory

Poul-Henning Kamp phk at FreeBSD.org
Mon Apr 13 22:46:13 CEST 2015


commit 900702bcff507a99f50a1d2ab09297d0e262d865
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Apr 13 20:45:31 2015 +0000

    Move each vcl into a subdirectory under the -n directory

diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index ae65533..410439e 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -85,7 +85,7 @@ enum jail_master_e {
 typedef int jail_init_f(char **);
 typedef void jail_master_f(enum jail_master_e);
 typedef void jail_subproc_f(enum jail_subproc_e);
-typedef void jail_make_workdir_f(const char *dname);
+typedef void jail_make_dir_f(const char *dname);
 typedef void jail_storage_file_f(int fd);
 
 struct jail_tech {
@@ -95,7 +95,8 @@ struct jail_tech {
 	jail_init_f		*init;
 	jail_master_f		*master;
 	jail_subproc_f		*subproc;
-	jail_make_workdir_f	*make_workdir;
+	jail_make_dir_f		*make_workdir;
+	jail_make_dir_f		*make_vcldir;
 	jail_storage_file_f	*storage_file;
 };
 
@@ -103,6 +104,7 @@ void VJ_Init(const char *j_arg);
 void VJ_master(enum jail_master_e jme);
 void VJ_subproc(enum jail_subproc_e jse);
 void VJ_make_workdir(const char *dname);
+void VJ_make_vcldir(const char *dname);
 void VJ_storage_file(int fd);
 
 extern const struct jail_tech jail_tech_unix;
diff --git a/bin/varnishd/mgt/mgt_jail.c b/bin/varnishd/mgt/mgt_jail.c
index f95bc81..b9a1ad9 100644
--- a/bin/varnishd/mgt/mgt_jail.c
+++ b/bin/varnishd/mgt/mgt_jail.c
@@ -163,6 +163,22 @@ VJ_make_workdir(const char *dname)
 }
 
 void
+VJ_make_vcldir(const char *dname)
+{
+
+	AN(dname);
+	CHECK_OBJ_NOTNULL(vjt, JAIL_TECH_MAGIC);
+	if (vjt->make_vcldir != NULL) {
+		vjt->make_vcldir(dname);
+		return;
+	}
+
+	if (mkdir(dname, 0755) < 0 && errno != EEXIST)
+		ARGV_ERR("Cannot create VCL directory '%s': %s\n",
+		    dname, strerror(errno));
+}
+
+void
 VJ_storage_file(int fd)
 {
 
diff --git a/bin/varnishd/mgt/mgt_jail_unix.c b/bin/varnishd/mgt/mgt_jail_unix.c
index 4f9122c..a10c645 100644
--- a/bin/varnishd/mgt/mgt_jail_unix.c
+++ b/bin/varnishd/mgt/mgt_jail_unix.c
@@ -177,7 +177,7 @@ vju_subproc(enum jail_subproc_e jse)
 #endif
 }
 
-static void
+static void __match_proto__(jail_make_dir_f)
 vju_make_workdir(const char *dname)
 {
 	int fd;
@@ -208,6 +208,16 @@ vju_make_workdir(const char *dname)
 	AZ(unlink("_.testfile"));
 }
 
+static void __match_proto__(jail_make_dir_f)
+vju_make_vcldir(const char *dname)
+{
+	AZ(seteuid(0));
+
+	AZ(mkdir(dname, 0755));
+	AZ(chown(dname, vju_uid, vju_gid));
+	AZ(seteuid(vju_uid));
+}
+
 static void
 vju_storage_file(int fd)
 {
@@ -223,6 +233,7 @@ const struct jail_tech jail_tech_unix = {
 	.init =		vju_init,
 	.master =	vju_master,
 	.make_workdir =	vju_make_workdir,
+	.make_vcldir =	vju_make_vcldir,
 	.storage_file =	vju_storage_file,
 	.subproc =	vju_subproc,
 };
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 78c9169..9de54e6 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -283,13 +283,19 @@ mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc,
 	INIT_OBJ(&vp, VCC_PRIV_MAGIC);
 	vp.src = vclsrc;
 
-	VSB_printf(sb, "./vcl_%s.c", vclname);
+	VSB_printf(sb, "vcl_%s", vclname);
+	AZ(VSB_finish(sb));
+	VJ_make_vcldir(VSB_data(sb));
+
+
+	VSB_clear(sb);
+	VSB_printf(sb, "vcl_%s/vgc.c", vclname);
 	AZ(VSB_finish(sb));
 	vp.srcfile = strdup(VSB_data(sb));
 	AN(vp.srcfile);
 	VSB_clear(sb);
 
-	VSB_printf(sb, "./vcl_%s.so", vclname);
+	VSB_printf(sb, "vcl_%s/vgc.so", vclname);
 	AZ(VSB_finish(sb));
 	vp.libfile = strdup(VSB_data(sb));
 	AN(vp.srcfile);



More information about the varnish-commit mailing list