v->args = "";
v->telnet = ":9001";
v->accept = ":9081";
+ v->cli_fd = -1;
VTAILQ_INSERT_TAIL(&varnishes, v, list);
return (v);
}
struct vsb *vsb;
int i;
+ printf("## %-4s Launch\n", v->name);
vsb = vsb_newauto();
AN(vsb);
vsb_printf(vsb, "cd ../varnishd &&");
exit (1);
}
printf("### %-4s CLI connection fd = %d\n", v->name, v->cli_fd);
+ assert(v->cli_fd >= 0);
}
/**********************************************************************
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);
}
static void
varnish_stop(struct varnish *v)
{
- void *p;
+ 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;
+
+ 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;
}
/**********************************************************************
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 */
varnish_stop(v);
continue;
}
+ if (!strcmp(*av, "-wait")) {
+ varnish_wait(v);
+ continue;
+ }
fprintf(stderr, "Unknown varnish argument: %s\n", *av);
exit (1);
}