]> git.dolda2000.com Git - ashd.git/commitdiff
lib: Allow reception of mtstdopen info structure.
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 13 Apr 2016 23:45:15 +0000 (01:45 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 13 Apr 2016 23:45:15 +0000 (01:45 +0200)
lib/mtio.c
lib/mtio.h
src/accesslog.c
src/callfcgi.c
src/callscgi.c
src/htparser.c
src/plaintcp.c
src/psendfile.c

index b2f55f8ef6e2c9ded84dbee955617f450f0adb06..d7f36ac82d31be22e5d5c9111476d16ee2a15e99 100644 (file)
 #include <mt.h>
 #include <mtio.h>
 
-struct stdiofd {
-    int fd;
-    int sock;
-    int timeout;
-};
-
 static ssize_t mtread(void *cookie, void *buf, size_t len)
 {
     struct stdiofd *d = cookie;
@@ -98,7 +92,7 @@ static int mtclose(void *cookie)
     return(0);
 }
 
-FILE *mtstdopen(int fd, int issock, int timeout, char *mode)
+FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop)
 {
     struct stdiofd *d;
     FILE *ret;
@@ -117,11 +111,13 @@ FILE *mtstdopen(int fd, int issock, int timeout, char *mode)
     d->fd = fd;
     d->sock = issock;
     d->timeout = timeout;
-    ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose);
-    if(!ret)
+    if(!(ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose))) {
        free(d);
-    else
-       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+       return(NULL);
+    }
+    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+    if(infop)
+       *infop = d;
     return(ret);
 }
 
index 2bc21fd39f966d3912ecac81acecd1fe17594616..75928ebe4a7e27c9d10b36a6fd6fadf4c1b6a176 100644 (file)
@@ -6,10 +6,16 @@
 #define EV_READ 1
 #define EV_WRITE 2
 
+struct stdiofd {
+    int fd;
+    int sock;
+    int timeout;
+};
+
 int block(int fd, int ev, time_t to);
 int ioloop(void);
 void exitioloop(int status);
-FILE *mtstdopen(int fd, int issock, int timeout, char *mode);
+FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop);
 void mtiopipe(FILE **read, FILE **write);
 
 #endif
index 1addb387a4db3db824e5e060057413e1386779d6..a3894bf248b071a5302c3a99a669d8579aa804b4 100644 (file)
@@ -249,10 +249,10 @@ static void filterreq(struct muth *mt, va_list args)
     data = defdata;
     data.req = req;
     gettimeofday(&data.start, NULL);
-    cl = mtstdopen(fd, 1, 600, "r+");
+    cl = mtstdopen(fd, 1, 600, "r+", NULL);
     if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
        goto out;
-    hd = mtstdopen(pfds[1], 1, 600, "r+");
+    hd = mtstdopen(pfds[1], 1, 600, "r+", NULL);
     if(sendreq(ch, req, pfds[0])) {
        close(pfds[0]);
        goto out;
index 6b04c20332b76d44a75964a624c76c2f13284ebb..8d33eef1d3c8f9d00758a178cbefc3cb4fd85f7d 100644 (file)
@@ -690,12 +690,12 @@ static void serve(struct muth *muth, va_list args)
     char buf[8192];
     
     sfd = reconn();
-    is = mtstdopen(fd, 1, 60, "r+");
-    os = mtstdopen(sfd, 1, 600, "r+");
+    is = mtstdopen(fd, 1, 60, "r+", NULL);
+    os = mtstdopen(sfd, 1, 600, "r+", NULL);
     
     outi = NULL;
     mtiopipe(&outi, &outo); mtiopipe(&erri, &erro);
-    mustart(outplex, mtstdopen(dup(sfd), 1, 600, "r+"), outo, FCGI_STDOUT, erro, FCGI_STDERR, NULL);
+    mustart(outplex, mtstdopen(dup(sfd), 1, 600, "r+", NULL), outo, FCGI_STDOUT, erro, FCGI_STDERR, NULL);
     mustart(errhandler, erri);
     
     if(begreq(os, 1))
index 3c26e333035602ba6b1d0a11179148c8ba4f6697..2483c49bd603a13ce549a6cc2569c5e2c79f9e00 100644 (file)
@@ -521,8 +521,8 @@ static void serve(struct muth *muth, va_list args)
     struct hthead *resp;
     
     sfd = reconn();
-    is = mtstdopen(fd, 1, 60, "r+");
-    os = mtstdopen(sfd, 1, 600, "r+");
+    is = mtstdopen(fd, 1, 60, "r+", NULL);
+    os = mtstdopen(sfd, 1, 600, "r+", NULL);
     
     bufinit(head);
     mkcgienv(req, &head);
index a20b32906ab25d0a98926c1515660999a47959b2..92445d7bf85f7554a7a6ef0066d28314963f63f7 100644 (file)
@@ -328,7 +328,7 @@ void serve(FILE *in, struct conn *conn)
        if(sendreq(plex, req, pfds[0]))
            break;
        close(pfds[0]);
-       out = mtstdopen(pfds[1], 1, 600, "r+");
+       out = mtstdopen(pfds[1], 1, 600, "r+", NULL);
 
        if(getheader(req, "content-type") != NULL) {
            if((hd = getheader(req, "content-length")) != NULL) {
index 05921660a16c8c6bf94a0deb34405fbb077050ca..1d3e2e71986e43d80dc3b67c5e22de2df527bd25 100644 (file)
@@ -156,7 +156,7 @@ void servetcp(struct muth *muth, va_list args)
     
     memset(&conn, 0, sizeof(conn));
     memset(&tcp, 0, sizeof(tcp));
-    in = mtstdopen(fd, 1, 60, "r+");
+    in = mtstdopen(fd, 1, 60, "r+", NULL);
     conn.pdata = &tcp;
     conn.initreq = initreq;
     tcp.fd = fd;
index f5c7fdd466c2519023c6412de353f9830989bb55..3e26f8f0033fff6caf0c99af58e4ac06eac57d93 100644 (file)
@@ -227,7 +227,7 @@ static void serve(struct muth *muth, va_list args)
     
     sfile = NULL;
     contype = NULL;
-    out = mtstdopen(fd, 1, 60, "r+");
+    out = mtstdopen(fd, 1, 60, "r+", NULL);
     
     if((file = getheader(req, "X-Ash-File")) == NULL) {
        flog(LOG_ERR, "psendfile: needs to be called with the X-Ash-File header");