--- parser3/src/targets/cgi/parser3.C 2002/11/19 14:39:56 1.199 +++ parser3/src/targets/cgi/parser3.C 2002/12/05 09:41:56 1.207 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_PARSER3_C="$Date: 2002/11/19 14:39:56 $"; +static const char* IDENT_PARSER3_C="$Date: 2002/12/05 09:41:56 $"; #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 @@ -58,6 +59,9 @@ static Pool global_pool(&global_pool_sto static bool cgi; ///< we were started as CGI? static bool mail_received=false; ///< we were started with -m option? [asked to parse incoming message to $mail:received] +// for signal handlers +Request *request=0; + // SAPI static void log(const char *fmt, va_list args) { @@ -125,7 +129,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); @@ -170,7 +174,7 @@ const char *const *SAPI::environment(Poo size_t SAPI::read_post(Pool& , char *buf, size_t max_bytes) { size_t read_size=0; do { - int chunk_size=read(fileno(stdin), + ssize_t chunk_size=read(fileno(stdin), buf+read_size, min(READ_POST_CHUNK_SIZE, max_bytes-read_size)); if(chunk_size<=0) break; @@ -220,6 +224,28 @@ 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 +static void SIGUSR1_handler(int /*sig*/){ + log_signal("SIGUSR1"); +} +#endif + +#ifdef SIGPIPE +static void SIGPIPE_handler(int /*sig*/){ + log_signal("SIGPIPE"); + if(request) + request->interrupt(); +} +#endif + /** main workhorse @@ -316,7 +342,10 @@ static void real_parser_handler( /*#endif*/ , true /* status_allowed */); - + + // get request ptr for signal handlers + ::request=&request; + char config_filespec_buf[MAX_STRING]; if(!config_filespec_cstr) { const char *config_by_env=getenv(PARSER_CONFIG_ENV_NAME); @@ -347,6 +376,9 @@ static void real_parser_handler( request.core( config_filespec_cstr, fail_on_config_read_problem, header_only); + + // no request [prevent signal handlers from accessing invalid memory] + ::request=0; // done_socks(); @@ -427,6 +459,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*/); @@ -542,6 +584,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; }