diff options
author | Grzegorz Nosek <root@localdomain.pl> | 2013-02-03 13:42:40 +0100 |
---|---|---|
committer | Grzegorz Nosek <root@localdomain.pl> | 2013-02-03 14:14:09 +0100 |
commit | 8aae1f5bf8d135d78e53c054876e2c9dc86936b9 (patch) | |
tree | 8ec9f48b35a4ef3052392ead83b240bc6f436797 | |
parent | 4ea36af0418d7f6592c33669432404f8251d5556 (diff) | |
download | fcgiwrap-8aae1f5bf8d135d78e53c054876e2c9dc86936b9.tar.xz fcgiwrap-8aae1f5bf8d135d78e53c054876e2c9dc86936b9.zip |
Unify CGI error handling
Use the same error handler for 403s and 502s. This basically ports
the required fixes from error_403 (previous commit) to the 502
error on failed exec(). Two user-visible side effects:
- error message now says "403 Forbidden" instead of "403"
- failed exec() gets logged over stderr
(also, use \r\n instead of \n as a line seprator but that has been
fixed up by the parent process before).
-rw-r--r-- | fcgiwrap.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -485,9 +485,10 @@ static void inherit_environment(void) } } -static void error_403(const char *reason, const char *filename) +static void cgi_error(const char *message, const char *reason, const char *filename) { - puts("Status: 403 Forbidden\nContent-type: text/plain\n\n403"); + printf("Status: %s\r\nContent-Type: text/plain\r\n\r\n%s\r\n", + message, message); fflush(stdout); if (filename) { fprintf(stderr, "%s (%s)\n", reason, filename); @@ -536,21 +537,20 @@ static void handle_fcgi_request(void) filename = get_cgi_filename(); inherit_environment(); if (!filename) - error_403("Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?", NULL); + cgi_error("403 Forbidden", "Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?", NULL); last_slash = strrchr(filename, '/'); if (!last_slash) - error_403("Script name must be a fully qualified path", filename); + cgi_error("403 Forbidden", "Script name must be a fully qualified path", filename); *last_slash = 0; if (chdir(filename) < 0) - error_403("Cannot chdir to script directory", filename); + cgi_error("403 Forbidden", "Cannot chdir to script directory", filename); *last_slash = '/'; execl(filename, filename, (void *)NULL); - puts("Status: 502 Bad Gateway\nContent-type: text/plain\n\n502"); - exit(99); + cgi_error("502 Bad Gateway", "Cannot execute script", filename); default: /* parent */ close(pipe_in[0]); |