X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdirplex%2Fdirplex.c;h=baf24fac7a845c9267560e118d21f906c9fd26f3;hb=b70b2d4f237082541d01b4b33abc86ef2b7b2223;hp=31920e625e717bab485ae6e56a6058c003674fd3;hpb=fd735432ca61308348e1f1eb1b79a42e357aa0b7;p=ashd.git diff --git a/src/dirplex/dirplex.c b/src/dirplex/dirplex.c index 31920e6..baf24fa 100644 --- a/src/dirplex/dirplex.c +++ b/src/dirplex/dirplex.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #ifdef HAVE_CONFIG_H @@ -69,8 +70,7 @@ static void handle(struct hthead *req, int fd, char *path, struct pattern *pat) simpleerror(fd, 500, "Configuration Error", "The server is erroneously configured. Handler %s was requested, but not declared.", pat->childnm); return; } - twd = NULL; - if((twd = ccf->path) != NULL) { + if((twd = ccf?ccf->path:NULL) != NULL) { if(!strcmp(twd, ".")) { twd = NULL; } else if(strncmp(path, twd, strlen(twd)) || (path[strlen(twd)] != '/')) { @@ -88,12 +88,25 @@ static void handle(struct hthead *req, int fd, char *path, struct pattern *pat) } } +static void handle404(struct hthead *req, int fd, char *path) +{ + struct child *ch; + struct config *ccf; + char *tmp; + + tmp = sstrdup(path); + ch = findchild(tmp, ".notfound", &ccf); + if(childhandle(ch, req, fd, chinit, ccf?ccf->path:NULL)) + simpleerror(fd, 500, "Server Error", "The request handler crashed."); + free(tmp); +} + static void handlefile(struct hthead *req, int fd, char *path) { struct pattern *pat; if((pat = findmatch(path, 0, 0)) == NULL) { - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, path); return; } handle(req, fd, path, pat); @@ -184,8 +197,8 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * char *newpath; int rv; - if(!el == '.') { - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + if(*el == '.') { + handle404(req, fd, sprintf3("%s/", path)); return(1); } if(!stat(sprintf3("%s/%s", path, el), &sb)) { @@ -205,7 +218,7 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * free(newpath); return(1); } - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, sprintf3("%s/", path)); return(1); } if(!strchr(el, '.') && ((newpath = findfile(path, el, NULL)) != NULL)) { @@ -236,7 +249,7 @@ static int checkdir(struct hthead *req, int fd, char *path, char *rest) if(*rest == '/') rest++; replrest(req, rest); - if(childhandle(ch, req, fd, chinit, ccf->path)) + if(childhandle(ch, req, fd, chinit, ccf?ccf->path:NULL)) simpleerror(fd, 500, "Server Error", "The request handler crashed."); return(1); } @@ -272,14 +285,15 @@ static int checkpath(struct hthead *req, int fd, char *path, char *rest) goto out; } if(strchr(el, '/') || (!*el && *rest)) { - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, sprintf3("%s/", path)); rv = 1; goto out; } if(!*el) { replrest(req, rest); handledir(req, fd, path); - return(1); + rv = 1; + goto out; } rv = checkentry(req, fd, path, rest, el); @@ -293,7 +307,16 @@ static void serve(struct hthead *req, int fd) { now = time(NULL); if(!checkpath(req, fd, ".", req->rest)) - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, "."); +} + +static void chldhandler(int sig) +{ + pid_t pid; + + do { + pid = waitpid(-1, NULL, WNOHANG); + } while(pid > 0); } static void sighandler(int sig) @@ -359,7 +382,7 @@ int main(int argc, char **argv) flog(LOG_ERR, "could not change directory to %s: %s", argv[optind], strerror(errno)); exit(1); } - signal(SIGCHLD, SIG_IGN); + signal(SIGCHLD, chldhandler); signal(SIGPIPE, sighandler); while(1) { if((fd = recvreq(0, &req)) < 0) {