r2718 - trunk/varnish-cache/bin/varnishtest

phk at projects.linpro.no phk at projects.linpro.no
Tue Jun 17 10:03:58 CEST 2008


Author: phk
Date: 2008-06-17 10:03:58 +0200 (Tue, 17 Jun 2008)
New Revision: 2718

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
Log:
Add varnish -wait and make varnish -stop mean the logical thing



Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2008-06-17 07:53:21 UTC (rev 2717)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2008-06-17 08:03:58 UTC (rev 2718)
@@ -146,6 +146,7 @@
 	v->args = "";
 	v->telnet = ":9001";
 	v->accept = ":9081";
+	v->cli_fd = -1;
 	VTAILQ_INSERT_TAIL(&varnishes, v, list);
 	return (v);
 }
@@ -182,6 +183,7 @@
 	struct vsb *vsb;
 	int i;
 
+	printf("##   %-4s Launch\n", v->name);
 	vsb = vsb_newauto();
 	AN(vsb);
 	vsb_printf(vsb, "cd ../varnishd &&");
@@ -226,6 +228,7 @@
 		exit (1);
 	}
 	printf("###  %-4s CLI connection fd = %d\n", v->name, v->cli_fd);
+	assert(v->cli_fd >= 0);
 }
 
 /**********************************************************************
@@ -236,7 +239,9 @@
 varnish_start(struct varnish *v)
 {
 
-	varnish_launch(v);
+	if (v->cli_fd < 0)
+		varnish_launch(v);
+	printf("##   %-4s Start\n", v->name);
 	varnish_ask_cli(v, "start", NULL);
 }
 
@@ -247,14 +252,33 @@
 static void
 varnish_stop(struct varnish *v)
 {
+
+	if (v->cli_fd < 0)
+		varnish_launch(v);
+	printf("##   %-4s Stop\n", v->name);
+	varnish_ask_cli(v, "stop", NULL);
+}
+
+/**********************************************************************
+ * Wait for a Varnish
+ */
+
+static void
+varnish_wait(struct varnish *v)
+{
 	void *p;
 
-	varnish_ask_cli(v, "stop", NULL);
+	if (v->cli_fd < 0)
+		return;
+	varnish_stop(v);
+	printf("##   %-4s Wait\n", v->name);
 	AZ(kill(v->pid, SIGKILL));
 	AZ(pthread_cancel(v->tp));
 	AZ(pthread_join(v->tp, &p));
 	close(v->fds[0]);
 	close(v->fds[1]);
+	close(v->cli_fd);
+	v->cli_fd = -1;
 }
 
 /**********************************************************************
@@ -366,6 +390,8 @@
 	if (av == NULL) {
 		/* Reset and free */
 		VTAILQ_FOREACH_SAFE(v, &varnishes, list, v2) {
+			if (v->cli_fd >= 0)
+				varnish_wait(v);
 			VTAILQ_REMOVE(&varnishes, v, list);
 			FREE_OBJ(v);
 			/* XXX: MEMLEAK */
@@ -421,6 +447,10 @@
 			varnish_stop(v);
 			continue;
 		}
+		if (!strcmp(*av, "-wait")) {
+			varnish_wait(v);
+			continue;
+		}
 		fprintf(stderr, "Unknown varnish argument: %s\n", *av);
 		exit (1);
 	}




More information about the varnish-commit mailing list