Commit 227a3944 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a dummy pipe to use for poll(2)'ing the death of varnishd,

while we wait for it to establish CLI connection.
parent 1eac7c26
......@@ -59,7 +59,7 @@ struct varnish {
struct vsb *storage;
struct vsb *args;
int fds[4];
int fds[6];
pid_t pid;
pthread_t tp;
......@@ -365,6 +365,7 @@ varnish_launch(struct varnish *v)
vtc_log(v->vl, 3, "CMD: %s", VSB_data(vsb));
AZ(pipe(&v->fds[0]));
AZ(pipe(&v->fds[2]));
AZ(pipe(&v->fds[4]));
v->pid = fork();
assert(v->pid >= 0);
if (v->pid == 0) {
......@@ -375,8 +376,11 @@ varnish_launch(struct varnish *v)
AZ(close(v->fds[1]));
AZ(close(v->fds[2]));
AZ(close(v->fds[3]));
for (i = 3; i <getdtablesize(); i++)
(void)close(i);
AZ(close(v->fds[4]));
for (i = 3; i <getdtablesize(); i++) {
if (v->fds[5] != i)
(void)close(i);
}
AZ(execl("/bin/sh", "/bin/sh", "-c", VSB_data(vsb), NULL));
exit(1);
} else {
......@@ -384,6 +388,7 @@ varnish_launch(struct varnish *v)
}
AZ(close(v->fds[0]));
AZ(close(v->fds[3]));
AZ(close(v->fds[5]));
v->fds[0] = v->fds[2];
v->fds[2] = v->fds[3] = -1;
VSB_delete(vsb);
......@@ -394,8 +399,8 @@ varnish_launch(struct varnish *v)
memset(fd, 0, sizeof fd);
fd[0].fd = v->cli_fd;
fd[0].events = POLLIN;
fd[1].fd = v->fds[0];
fd[1].events = POLLHUP;
fd[1].fd = v->fds[4];
fd[1].events = POLLIN|POLLHUP;
#ifdef __APPLE__
/*
* OSX cannot poll a pipe for POLLHUP only, poll just returns
......@@ -425,6 +430,7 @@ varnish_launch(struct varnish *v)
return;
}
AZ(close(v->fds[4]));
AZ(close(v->cli_fd));
v->cli_fd = nfd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment