Commit Diff


commit - ef945cf4157bc8239c6da682a89ba60b11cc0e26
commit + ea976e8743ad3b3263faae00d88e40bcf727097d
blob - 1868156747dbd6b76fde440953f1256f5cf35312
blob + 8e25bd13254a1e570f1f8a04f3fc9ca2bb721b73
--- ex.c
+++ ex.c
@@ -128,10 +128,12 @@ static int
 launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
     struct location *loc)
 {
-	int p[2];		/* read end, write end */
+	int p[2], errp[2];	/* read end, write end */
 
 	if (pipe(p) == -1)
 		return -1;
+	if (pipe(errp) == -1)
+		return -1;
 
 	switch (fork()) {
 	case -1:
@@ -147,6 +149,10 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct
 		if (dup2(p[1], 1) == -1)
 			goto childerr;
 
+		close(errp[0]);
+		if (dup2(errp[1], 2) == -1)
+			goto childerr;
+
 		ex = xasprintf("%s/%s", loc->dir, req->spath);
 
 		serialize_iri(iri, iribuf, sizeof(iribuf));
@@ -224,6 +230,7 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct
 
 	default:
 		close(p[1]);
+		close(errp[1]);
 		mark_nonblock(p[0]);
 		return p[0];
 	}