diff options
author | Grzegorz Nosek <root@localdomain.pl> | 2013-02-03 13:32:17 +0100 |
---|---|---|
committer | Grzegorz Nosek <root@localdomain.pl> | 2013-02-03 14:14:09 +0100 |
commit | 4ea36af0418d7f6592c33669432404f8251d5556 (patch) | |
tree | 39f46089fac7ae8055f193a7fac2b69a4f33a733 | |
parent | fa4b1049078dc6e1a4ec9e897740076e91718ea4 (diff) | |
download | fcgiwrap-4ea36af0418d7f6592c33669432404f8251d5556.tar.xz fcgiwrap-4ea36af0418d7f6592c33669432404f8251d5556.zip |
Fix 403 error handling
Report 403 errors over normal stdout/stderr (after setting up the
pipes). Properly reporting the error response over stdout requires:
- flushing the I/O, which would otherwise get buffered
- skipping atexit handlers (would otherwise close the FCGI connection
cleanly, interfering with the parent process still trying to talk
over it)
-rw-r--r-- | fcgiwrap.c | 40 |
1 files changed, 21 insertions, 19 deletions
@@ -487,14 +487,15 @@ static void inherit_environment(void) static void error_403(const char *reason, const char *filename) { - FCGI_fputs("Status: 403 Forbidden\nContent-type: text/plain\n\n403", FCGI_stdout); + puts("Status: 403 Forbidden\nContent-type: text/plain\n\n403"); + fflush(stdout); if (filename) { - FCGI_fprintf(FCGI_stderr, "%s (%s)\n", reason, filename); + fprintf(stderr, "%s (%s)\n", reason, filename); } else { - FCGI_fputs(reason, FCGI_stderr); - FCGI_fputc('\n', FCGI_stderr); + fputs(reason, stderr); + fputc('\n', stderr); } - exit(99); + _exit(99); } static void handle_fcgi_request(void) @@ -517,6 +518,21 @@ static void handle_fcgi_request(void) goto err_fork; case 0: /* child */ + close(pipe_in[1]); + close(pipe_out[0]); + close(pipe_err[0]); + + dup2(pipe_in[0], 0); + dup2(pipe_out[1], 1); + dup2(pipe_err[1], 2); + + close(pipe_in[0]); + close(pipe_out[1]); + close(pipe_err[1]); + + signal(SIGCHLD, SIG_DFL); + signal(SIGPIPE, SIG_DFL); + filename = get_cgi_filename(); inherit_environment(); if (!filename) @@ -532,20 +548,6 @@ static void handle_fcgi_request(void) *last_slash = '/'; - close(pipe_in[1]); - close(pipe_out[0]); - close(pipe_err[0]); - - dup2(pipe_in[0], 0); - dup2(pipe_out[1], 1); - dup2(pipe_err[1], 2); - - close(pipe_in[0]); - close(pipe_out[1]); - close(pipe_err[1]); - - signal(SIGCHLD, SIG_DFL); - signal(SIGPIPE, SIG_DFL); execl(filename, filename, (void *)NULL); puts("Status: 502 Bad Gateway\nContent-type: text/plain\n\n502"); exit(99); |