X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdirplex.c;h=699819f4952ccfb7bc1f79de590f6b81e233802e;hb=755faed02a98d53ed7dd2889e36f177d926f4638;hp=6dccff56b40053dd02cdd6cd8021bb5473212cdd;hpb=06c1a7183754349e29a6f4656d88d3f89e4f448a;p=ashd.git diff --git a/src/dirplex.c b/src/dirplex.c index 6dccff5..699819f 100644 --- a/src/dirplex.c +++ b/src/dirplex.c @@ -37,9 +37,6 @@ #include #include -#define CH_SOCKET 0 -#define CH_FORK 1 - #define PAT_BASENAME 0 #define PAT_PATHNAME 1 #define PAT_ALL 2 @@ -337,29 +334,6 @@ out: return(pat); } -static void forkchild(struct child *ch) -{ - ch->fd = stdmkchild(ch->argv); -} - -static void passreq(struct child *ch, struct hthead *req, int fd) -{ - if(ch->fd < 0) - forkchild(ch); - if(sendreq(ch->fd, req, fd)) { - if(errno == EPIPE) { - /* Assume that the child has crashed and restart it. */ - forkchild(ch); - if(!sendreq(ch->fd, req, fd)) - return; - } - flog(LOG_ERR, "could not pass on request to child %s: %s", ch->name, strerror(errno)); - close(ch->fd); - ch->fd = -1; - simpleerror(fd, 500, "Server Error", "The request handler crashed."); - } -} - static void handlefile(struct hthead *req, int fd, char *path) { struct pattern *pat; @@ -376,11 +350,8 @@ static void handlefile(struct hthead *req, int fd, char *path) return; } - if(ch->type == CH_SOCKET) { - passreq(ch, req, fd); - } else if(ch->type == CH_FORK) { - stdforkserve(ch->argv, req, fd); - } + if(childhandle(ch, req, fd)) + simpleerror(fd, 500, "Server Error", "The request handler crashed."); } static void handledir(struct hthead *req, int fd, char *path) @@ -442,6 +413,10 @@ static void serve(struct hthead *req, int fd) else path = sprintf2("%s/%s", path, p); free(tmp); + if(p2 == NULL) { + stdredir(req, fd, 301, sprintf3("%s/", p)); + goto out; + } if(checkdir(req, fd, path)) break; goto next;