r4487 - trunk/varnish-cache/bin/varnishtest

phk at projects.linpro.no phk at projects.linpro.no
Mon Jan 25 21:46:49 CET 2010


Author: phk
Date: 2010-01-25 21:46:49 +0100 (Mon, 25 Jan 2010)
New Revision: 4487

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/bin/varnishtest/vtc.h
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
Log:
Go further with the uniquely named tmpdir thing and put the varnishd
workdir below there as well.

Do not remove the tmpdir if we have verbosity and failure, otherwise do.



Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2010-01-25 20:04:24 UTC (rev 4486)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2010-01-25 20:46:49 UTC (rev 4487)
@@ -42,7 +42,6 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include "compat/asprintf.h"
 
 #include "libvarnish.h"
 #include "vsb.h"
@@ -59,6 +58,7 @@
 int		vtc_error;		/* Error encountered */
 int		vtc_stop;		/* Stops current test without error */
 pthread_t	vtc_thread;
+char		*vtc_tmpdir;
 
 /**********************************************************************
  * Macro facility
@@ -140,7 +140,7 @@
 }
 
 struct vsb *
-macro_expand(char *name)
+macro_expand(const char *name)
 {
 	struct vsb *vsb;
 	char *p, *q;
@@ -525,7 +525,7 @@
 	static struct vtclog	*vl;
 	double tmax, t0, t00;
 	const char *nmax;
-	char *tmpdir, *cmd;
+	char cmd[BUFSIZ];
 
 	setbuf(stdout, NULL);
 	setbuf(stderr, NULL);
@@ -556,10 +556,10 @@
 	init_macro();
 	init_sema();
 
-	tmpdir = tempnam(NULL, "vtc");
-	AN(tmpdir);
-	mkdir(tmpdir, 0700);
-	macro_def(vl, NULL, "tmpdir", tmpdir);
+	vtc_tmpdir = tempnam(NULL, "vtc");
+	AN(vtc_tmpdir);
+	AZ(mkdir(vtc_tmpdir, 0700));
+	macro_def(vl, NULL, "tmpdir", vtc_tmpdir);
 	vtc_thread = pthread_self();
 	tmax = 0;
 	nmax = NULL;
@@ -579,12 +579,12 @@
 			break;
 	}
 
-	/* XXX this will always remove the tmpdir even on failures.
-	 * Maybe we should keep it in that case? */
-	assert(asprintf(&cmd, "rm -rf %s", tmpdir) > 0);
-	AZ(system(cmd));
-	free(tmpdir);
-	free(cmd);
+	/* Remove tmpdir on success or non-verbosity */
+	if (vtc_error == 0 || vtc_verbosity == 0) {
+		bprintf(cmd, "rm -rf %s", vtc_tmpdir);
+		AZ(system(cmd));
+		free(vtc_tmpdir);
+	}
 
 	if (vtc_error)
 		return (2);

Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h	2010-01-25 20:04:24 UTC (rev 4486)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h	2010-01-25 20:46:49 UTC (rev 4487)
@@ -60,6 +60,7 @@
 extern int vtc_error;		/* Error, bail out */
 extern int vtc_stop;		/* Abandon current test, no error */
 extern pthread_t	vtc_thread;
+extern char *vtc_tmpdir;
 
 void init_sema(void);
 
@@ -78,4 +79,4 @@
 
 void macro_def(struct vtclog *vl, const char *instance, const char *name,
     const char *fmt, ...);
-struct vsb *macro_expand(char *name);
+struct vsb *macro_expand(const char *name);

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-01-25 20:04:24 UTC (rev 4486)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-01-25 20:46:49 UTC (rev 4487)
@@ -46,7 +46,6 @@
 #include <sys/wait.h>
 #include <sys/socket.h>
 
-#include "compat/asprintf.h"
 #include "vqueue.h"
 #include "miniobj.h"
 #include "libvarnish.h"
@@ -144,22 +143,19 @@
 varnish_new(const char *name)
 {
 	struct varnish *v;
-	char *c;
+	char buf[1024];
 
 	AN(name);
 	ALLOC_OBJ(v, VARNISH_MAGIC);
 	AN(v);
 	REPLACE(v->name, name);
 
-	if (getuid() == 0)
-		assert(asprintf(&v->workdir, "/tmp/__%s", name) >= 0);
-	else
-		assert(asprintf(&v->workdir, "/tmp/__%s.%d", name, getuid()) >= 0);
+	bprintf(buf, "%s/%s", vtc_tmpdir, name);
+	v->workdir = strdup(buf);
 	AN(v->workdir);
 
-	assert(asprintf(&c, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir) >= 0);
-	AN(c);
-	AZ(system(c));
+	bprintf(buf, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir);
+	AZ(system(buf));
 
 	v->vl = vtc_logopen(name);
 	AN(v->vl);



More information about the varnish-commit mailing list