X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=src%2Fcallcgi.c;h=3a28880b41ad03b99a4000dcf78e2ecdda9ed1f2;hp=3add3edbd0c7f0721c58b5fb8f9cbaac2fafd7b6;hb=18838a2eddc3ae7fdc8f3fefb8cd83c012328a5e;hpb=056f947352274dd1f6ec51b03c423c12e3828623 diff --git a/src/callcgi.c b/src/callcgi.c index 3add3ed..3a28880 100644 --- a/src/callcgi.c +++ b/src/callcgi.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -85,7 +86,6 @@ static char *absolutify(char *file) static pid_t forkchild(int inpath, char *prog, char *file, char *method, char *url, char *rest, int *infd, int *outfd) { - int i; char *qp, **env, *name; int inp[2], outp[2]; pid_t pid; @@ -98,12 +98,12 @@ static pid_t forkchild(int inpath, char *prog, char *file, char *method, char *u exit(1); } if(pid == 0) { - close(inp[1]); - close(outp[0]); dup2(inp[0], 0); dup2(outp[1], 1); - for(i = 3; i < FD_SETSIZE; i++) - close(i); + close(inp[0]); + close(inp[1]); + close(outp[0]); + close(outp[1]); if((qp = strchr(url, '?')) != NULL) *(qp++) = 0; putenv(sprintf2("SERVER_SOFTWARE=ashd/%s", VERSION)); @@ -343,6 +343,7 @@ int main(int argc, char **argv, char **envp) FILE *in, *out; char **headers; pid_t child; + int estat; environ = envp; signal(SIGPIPE, SIG_IGN); @@ -404,5 +405,14 @@ int main(int argc, char **argv, char **envp) printf("\n"); if(passdata(out, stdout)) kill(child, SIGINT); - return(0); + if(waitpid(child, &estat, 0) == child) { + if(WCOREDUMP(estat)) + flog(LOG_WARNING, "CGI handler `%s' dumped core", prog); + if(WIFEXITED(estat) && !WEXITSTATUS(estat)) + return(0); + else + return(1); + } + flog(LOG_WARNING, "could not wait for CGI handler: %s", strerror(errno)); + return(1); }