Sun, 30 Oct 2016 10:22:00 +0100
adds more error handling
src/server/daemon/main.c | file | annotate | diff | comparison | revisions | |
src/server/safs/cgi.c | file | annotate | diff | comparison | revisions |
--- a/src/server/daemon/main.c Sat Oct 29 21:04:10 2016 +0200 +++ b/src/server/daemon/main.c Sun Oct 30 10:22:00 2016 +0100 @@ -152,6 +152,10 @@ signal(SIGUSR1, sig_usr1_reload); signal(SIGTERM, sig_term); signal(SIGINT, sig_term); + + struct sigaction act; + act.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &act, NULL); /* start webserver */ int status;
--- a/src/server/safs/cgi.c Sat Oct 29 21:04:10 2016 +0200 +++ b/src/server/safs/cgi.c Sun Oct 30 10:22:00 2016 +0100 @@ -36,6 +36,8 @@ #include "../util/pblock.h" #include "../../ucx/string.h" +#include "../util/io.h" + #include "cgiutils.h" #define CGI_VARS 32 @@ -106,15 +108,16 @@ // read from child CGIResponseParser *parser = cgi_parser_new(sn, rq); WSBool cgiheader = TRUE; - + ssize_t wr = 0; + int result = REQ_PROCEED; while((r = read(cgip.out[0], buf, 4096)) > 0) { if(cgiheader) { size_t pos; int ret = cgi_parse_response(parser, buf, r, &pos); if(ret == -1) { protocol_status(sn, rq, 500, NULL); - cgi_parser_free(parser); - return REQ_ABORTED; + result = REQ_ABORTED; + break; } else if(ret == 0) { } else if(ret == 1) { @@ -124,16 +127,24 @@ } http_start_response(sn, rq); if(pos < r) { - net_write(sn->csd, buf+pos, r-pos); + wr = net_write(sn->csd, &buf[pos], r-pos); + if(wr <= 0) { + result = REQ_ABORTED; + break; + } } } } else { - net_write(sn->csd, buf, r); + wr = net_write(sn->csd, buf, r); + if(wr <= 0) { + result = REQ_ABORTED; + break; + } } } cgi_parser_free(parser); - return REQ_PROCEED; + return result; } int cgi_start(CGIProcess *p, char *path, char *const argv[], char *const envp[]) {