Create the passed socket explicitly in htparser rather than generally in sendreq().
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 18 Dec 2008 04:17:44 +0000 (05:17 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 18 Dec 2008 04:37:00 +0000 (05:37 +0100)
lib/req.c
lib/req.h
src/htparser.c

index 0ede229..db84e55 100644 (file)
--- a/lib/req.c
+++ b/lib/req.c
@@ -121,14 +121,11 @@ void headappheader(struct hthead *head, const char *name, const char *val)
     head->headers[i][1] = sstrdup(val);
 }
 
-int sendreq(int sock, struct hthead *req)
+int sendreq(int sock, struct hthead *req, int fd)
 {
     int ret, i;
-    int pfds[2];
     struct charbuf buf;
     
-    if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
-       return(-1);
     bufinit(buf);
     bufcatstr2(buf, req->method);
     bufcatstr2(buf, req->url);
@@ -139,15 +136,12 @@ int sendreq(int sock, struct hthead *req)
        bufcatstr2(buf, req->headers[i][1]);
     }
     bufcatstr2(buf, "");
-    ret = sendfd(sock, pfds[0], buf.b, buf.d);
+    ret = sendfd(sock, fd, buf.b, buf.d);
     buffree(buf);
-    close(pfds[0]);
-    if(ret < 0) {
-       close(pfds[1]);
+    if(ret < 0)
        return(-1);
-    } else {
-       return(pfds[1]);
-    }
+    else
+       return(0);
 }
 
 int recvreq(int sock, struct hthead **reqp)
index 942ff35..7fc70be 100644 (file)
--- a/lib/req.h
+++ b/lib/req.h
@@ -15,7 +15,7 @@ void freehthead(struct hthead *head);
 char *getheader(struct hthead *head, char *name);
 void headpreheader(struct hthead *head, const char *name, const char *val);
 void headappheader(struct hthead *head, const char *name, const char *val);
-int sendreq(int sock, struct hthead *req);
+int sendreq(int sock, struct hthead *req, int fd);
 int recvreq(int sock, struct hthead **reqp);
 void replrest(struct hthead *head, char *rest);
 
index 4924b98..5d7a932 100644 (file)
@@ -300,6 +300,7 @@ static void serve(struct muth *muth, va_list args)
     vavar(int, fd);
     vavar(struct sockaddr_storage, name);
     int cfd;
+    int pfds[2];
     char old;
     char *hd, *p;
     struct charbuf inbuf, outbuf;
@@ -352,8 +353,12 @@ static void serve(struct muth *muth, va_list args)
        }
        if(block(plex, EV_WRITE, 60) <= 0)
            goto out;
-       if((cfd = sendreq(plex, req)) < 0)
+       if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
            goto out;
+       if(sendreq(plex, req, pfds[0]))
+           goto out;
+       close(pfds[0]);
+       cfd = pfds[1];
 
        /*
         * If there is message data, pass it: