|
|
| version 1.331, 2020/12/15 20:57:56 | version 1.340, 2020/12/21 23:35:50 |
|---|---|
| Line 14 volatile const char * IDENT_PARSER3_C="$ | Line 14 volatile const char * IDENT_PARSER3_C="$ |
| #include "pa_common.h" | #include "pa_common.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_version.h" | #include "pa_version.h" |
| #include "pa_threads.h" | |
| #include "pa_vconsole.h" | #include "pa_vconsole.h" |
| #include "pa_sapi_info.h" | #include "pa_sapi_info.h" |
| Line 58 static const char* filespec_4log = NULL; | Line 59 static const char* filespec_4log = NULL; |
| // SAPI | // SAPI |
| static void log(const char* fmt, va_list args) { | static void pa_log(const char* fmt, va_list args) { |
| bool opened=false; | bool opened=false; |
| FILE *f=0; | FILE *f=0; |
| Line 98 static void log(const char* fmt, va_list | Line 99 static void log(const char* fmt, va_list |
| time_t t=time(0); | time_t t=time(0); |
| if(const char* stamp=ctime(&t)) { // never saw that | if(const char* stamp=ctime(&t)) { // never saw that |
| if(size_t len=strlen(stamp)) // saw once stamp being ="" | if(size_t len=strlen(stamp)) // saw once stamp being ="" |
| fprintf(f, "[%.*s] [%u] ", (int)len-1, stamp, (unsigned int)getpid() ); | fprintf(f, "[%.*s] [%u] ", (int)len-1, stamp, (unsigned int)pa_get_thread_id() ); |
| } | } |
| // message | // message |
| Line 118 static void log(const char* fmt, va_list | Line 119 static void log(const char* fmt, va_list |
| fflush(f); | fflush(f); |
| } | } |
| #ifdef PA_DEBUG_CGI_ENTRY_EXIT | void pa_log(const char* fmt, ...) { |
| static void log(const char* fmt, ...) { | |
| va_list args; | va_list args; |
| va_start(args,fmt); | va_start(args,fmt); |
| log(fmt, args); | pa_log(fmt, args); |
| va_end(args); | va_end(args); |
| } | } |
| #endif | |
| // appends to parser3.log located next to the config file if openable, to stderr otherwize | // appends to parser3.log located next to the config file if openable, to stderr otherwize |
| void SAPI::log(SAPI_Info&, const char* fmt, ...) { | void SAPI::log(SAPI_Info&, const char* fmt, ...) { |
| va_list args; | va_list args; |
| va_start(args,fmt); | va_start(args,fmt); |
| ::log(fmt, args); | pa_log(fmt, args); |
| va_end(args); | va_end(args); |
| } | } |
| Line 140 void SAPI::die(const char* fmt, ...) { | Line 139 void SAPI::die(const char* fmt, ...) { |
| // logging first, first vsnprintf | // logging first, first vsnprintf |
| va_start(args,fmt); | va_start(args,fmt); |
| ::log(fmt, args); | pa_log(fmt, args); |
| va_end(args); | va_end(args); |
| // inform user, second vsnprintf | // inform user, second vsnprintf |
| Line 201 static void log_signal(const char* signa | Line 200 static void log_signal(const char* signa |
| SAPI::log(*sapiInfo, "%s received %s processing request", signal_name, request ? "while" : "before or after"); | SAPI::log(*sapiInfo, "%s received %s processing request", signal_name, request ? "while" : "before or after"); |
| } | } |
| #ifdef SIGUSR1 | |
| static void SIGUSR1_handler(int /*sig*/){ | |
| log_signal("SIGUSR1"); | |
| } | |
| #endif | |
| #ifdef SIGPIPE | #ifdef SIGPIPE |
| #define SIGPIPE_NAME "SIGPIPE" | #define SIGPIPE_NAME "SIGPIPE" |
| static const String sigpipe_name(SIGPIPE_NAME); | static const String sigpipe_name(SIGPIPE_NAME); |
| Line 316 static void connection_handler(SAPI_Info | Line 309 static void connection_handler(SAPI_Info |
| try { | try { |
| memset(&request_info, 0, sizeof(request_info)); | memset(&request_info, 0, sizeof(request_info)); |
| connection.read_header(); | if(!connection.read_header()) |
| return; // ignore "void" connections | |
| info.populate_env(); | info.populate_env(); |
| char document_root_buf[MAX_STRING]; | char document_root_buf[MAX_STRING]; |
| Line 339 static void connection_handler(SAPI_Info | Line 333 static void connection_handler(SAPI_Info |
| r.core(config_filespec, strcasecmp(request_info.method, "HEAD")==0, String("httpd-main")); | r.core(config_filespec, strcasecmp(request_info.method, "HEAD")==0, String("httpd-main")); |
| } catch(const Exception& e) { // exception in connection handling or unhandled exception | } catch(const Exception& e) { // exception in connection handling or unhandled exception |
| SAPI::log(info, "%s", e.comment()); | SAPI::log(info, "%s", e.comment()); |
| SAPI::send_error(info, e.comment(), info.exception_http_status(e.type())); | const char *status = info.exception_http_status(e.type()); |
| if(*status){ | |
| info.clear_response_headers(); | |
| SAPI::send_error(info, e.comment(), status); | |
| } | |
| } | } |
| } | } |
| Line 391 static void httpd_mode() { | Line 389 static void httpd_mode() { |
| connection.sock = -1; | connection.sock = -1; |
| break; | break; |
| #else | #else |
| #ifdef HAVE_TLS | |
| pthread_t thread; | pthread_t thread; |
| pthread_attr_t attr; | pthread_attr_t attr; |
| pthread_attr_init(&attr); | pthread_attr_init(&attr); |
| Line 400 static void httpd_mode() { | Line 399 static void httpd_mode() { |
| throw Exception("httpd.fork", 0, "thread creation failed (%d)", result); | throw Exception("httpd.fork", 0, "thread creation failed (%d)", result); |
| connection.sock=-1; | connection.sock=-1; |
| break; | break; |
| #endif | |
| case HTTPD_Server::PARALLEL: | case HTTPD_Server::PARALLEL: |
| pid=fork(); | pid=fork(); |
| if(pid<0) | if(pid<0) |
| Line 589 int main(int argc, char *argv[]) { | Line 589 int main(int argc, char *argv[]) { |
| bool cgi=(getenv("SERVER_SOFTWARE") || getenv("SERVER_NAME") || getenv("GATEWAY_INTERFACE") || getenv("REQUEST_METHOD")) && !getenv("PARSER_VERSION"); | bool cgi=(getenv("SERVER_SOFTWARE") || getenv("SERVER_NAME") || getenv("GATEWAY_INTERFACE") || getenv("REQUEST_METHOD")) && !getenv("PARSER_VERSION"); |
| sapiInfo = cgi ? new SAPI_Info_CGI() : new SAPI_Info(); | sapiInfo = cgi ? new SAPI_Info_CGI() : new SAPI_Info(); |
| #ifdef SIGUSR1 | |
| signal(SIGUSR1, SIGUSR1_handler); | |
| #endif | |
| #ifdef SIGPIPE | #ifdef SIGPIPE |
| signal(SIGPIPE, SIGPIPE_handler); | signal(SIGPIPE, SIGPIPE_handler); |
| #endif | #endif |