From: Fredrik Tolf Date: Wed, 13 Apr 2016 23:45:15 +0000 (+0200) Subject: lib: Allow reception of mtstdopen info structure. X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=commitdiff_plain;h=b71ad67f41a9e99bd243d57b5038de28f1696f27 lib: Allow reception of mtstdopen info structure. --- diff --git a/lib/mtio.c b/lib/mtio.c index b2f55f8..d7f36ac 100644 --- a/lib/mtio.c +++ b/lib/mtio.c @@ -32,12 +32,6 @@ #include #include -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); } diff --git a/lib/mtio.h b/lib/mtio.h index 2bc21fd..75928eb 100644 --- a/lib/mtio.h +++ b/lib/mtio.h @@ -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 diff --git a/src/accesslog.c b/src/accesslog.c index 1addb38..a3894bf 100644 --- a/src/accesslog.c +++ b/src/accesslog.c @@ -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; diff --git a/src/callfcgi.c b/src/callfcgi.c index 6b04c20..8d33eef 100644 --- a/src/callfcgi.c +++ b/src/callfcgi.c @@ -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)) diff --git a/src/callscgi.c b/src/callscgi.c index 3c26e33..2483c49 100644 --- a/src/callscgi.c +++ b/src/callscgi.c @@ -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); diff --git a/src/htparser.c b/src/htparser.c index a20b329..92445d7 100644 --- a/src/htparser.c +++ b/src/htparser.c @@ -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) { diff --git a/src/plaintcp.c b/src/plaintcp.c index 0592166..1d3e2e7 100644 --- a/src/plaintcp.c +++ b/src/plaintcp.c @@ -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; diff --git a/src/psendfile.c b/src/psendfile.c index f5c7fdd..3e26f8f 100644 --- a/src/psendfile.c +++ b/src/psendfile.c @@ -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");