[experimental-ims] 227a394 Add a dummy pipe to use for poll(2)'ing the death of varnishd, while we wait for it to establish CLI connection.

Poul-Henning Kamp phk at FreeBSD.org
Thu Dec 18 10:27:45 CET 2014


commit 227a394496d089bc36d03a0e40605010c969019d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed May 2 09:53:09 2012 +0000

    Add a dummy pipe to use for poll(2)'ing the death of varnishd,
    while we wait for it to establish CLI connection.

diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index e493ae7..ed55353 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -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;
 



More information about the varnish-commit mailing list