--- parser3/src/targets/cgi/parser3.C 2002/11/20 13:37:23 1.201 +++ parser3/src/targets/cgi/parser3.C 2002/12/05 10:43:23 1.209 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_PARSER3_C="$Date: 2002/11/20 13:37:23 $"; +static const char* IDENT_PARSER3_C="$Date: 2002/12/05 10:43:23 $"; #include "pa_config_includes.h" @@ -20,6 +20,7 @@ static const char* IDENT_PARSER3_C="$Dat #include "pa_request.h" #include "pa_socks.h" #include "pa_version.h" + #include "pool_storage.h" #ifdef WIN32 @@ -87,6 +88,9 @@ static void log(const char *fmt, va_list if(!opened) f=stderr; + // use no memory [so that we could log out-of-memory error] + setbuf(f, 0); // stderr stream is unbuffered by default, but still... + // prefix time_t t=time(0); if(const char *stamp=ctime(&t)) { // never saw that @@ -128,7 +132,7 @@ void SAPI::die(const char *fmt, ...) { // log // logging is more important than user - // she can cancel download, we'd get SIG_PIPE, + // she can cancel download, we'd get SIGPIPE, // nothing would be logged then ::log(fmt, args); @@ -205,10 +209,10 @@ void SAPI::send_body(Pool& , const void // static void full_file_spec(const char *file_name, char *buf, size_t buf_size) { - if(file_name) + if(file_name && *file_name) if(file_name[0]=='/' #ifdef WIN32 - || (file_name[0] && file_name[1]==':') + || file_name[1]==':' #endif ) strncpy(buf, file_name, buf_size); @@ -223,15 +227,23 @@ static void full_file_spec(const char *f #endif } +static void log_signal(const char *signal_name) { + SAPI::log(global_pool, request? "%s received. uri=%s, qs=%s" + :"%s received. no request being processed", + signal_name, + request && request->info.uri?request->info.uri:"-", + request && request->info.query_string?request->info.query_string:"-"); +} + #ifdef SIGUSR1 -void SIGUSR1_Handler(int /*sig*/){ - SAPI::log(global_pool, "SIGUSR1 received. url=", request?request->info.uri:""); +static void SIGUSR1_handler(int /*sig*/){ + log_signal("SIGUSR1"); } #endif #ifdef SIGPIPE -void SIGPIPE_Handler(int /*sig*/){ - SAPI::log(global_pool, "SIGPIPE received. url=", request?request->info.uri:""); +static void SIGPIPE_handler(int /*sig*/){ + log_signal("SIGPIPE"); if(request) request->interrupt(); } @@ -336,14 +348,6 @@ static void real_parser_handler( // get request ptr for signal handlers ::request=&request; -#ifdef SIGUSR1 - if(signal(SIGUSR1, SIGUSR1_Handler)==SIG_ERR) - SAPI::die("Can not set handler for SIGUSR1"); -#endif -#ifdef SIGPIPE - if(signal(SIGPIPE, SIGPIPE_Handler)==SIG_ERR) - SAPI::die("Can not set handler for SIGPIPE"); -#endif char config_filespec_buf[MAX_STRING]; if(!config_filespec_cstr) { @@ -458,6 +462,16 @@ static void usage(const char *program) { } int main(int argc, char *argv[]) { +#ifdef SIGUSR1 + if(signal(SIGUSR1, SIGUSR1_handler)==SIG_ERR) + SAPI::die("Can not set handler for SIGUSR1"); +#endif +#ifdef SIGPIPE + if(signal(SIGPIPE, SIGPIPE_handler)==SIG_ERR) + SAPI::die("Can not set handler for SIGPIPE"); +#endif + + #ifdef DEBUG_MAILRECEIVE if(FILE *fake_in=fopen(DEBUG_MAILRECEIVE, "rt")) { dup2(fake_in->_file, 0/*STDIN_FILENO*/); @@ -573,6 +587,7 @@ int main(int argc, char *argv[]) { if(!cgi) SAPI::send_body(global_pool, "\n", 1); #endif -//_asm int 3; + + //_asm int 3; return 0; }