--- parser3/src/targets/cgi/parser3.C 2002/10/15 10:05:01 1.198 +++ parser3/src/targets/cgi/parser3.C 2002/11/20 13:37:23 1.201 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_PARSER3_C="$Date: 2002/10/15 10:05:01 $"; +static const char* IDENT_PARSER3_C="$Date: 2002/11/20 13:37:23 $"; #include "pa_config_includes.h" @@ -58,6 +58,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) { @@ -170,7 +173,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 +223,20 @@ static void full_file_spec(const char *f #endif } +#ifdef SIGUSR1 +void SIGUSR1_Handler(int /*sig*/){ + SAPI::log(global_pool, "SIGUSR1 received. url=", request?request->info.uri:""); +} +#endif + +#ifdef SIGPIPE +void SIGPIPE_Handler(int /*sig*/){ + SAPI::log(global_pool, "SIGPIPE received. url=", request?request->info.uri:""); + if(request) + request->interrupt(); +} +#endif + /** main workhorse @@ -288,7 +305,6 @@ static void real_parser_handler( 0, "CGI: no PATH_INFO defined(in reinventing REQUEST_URI)"); -#ifndef WIN32 // they've changed this under IIS5. if(const char *script_name=SAPI::get_env(request_pool, "SCRIPT_NAME")) { size_t script_name_len=strlen(script_name); @@ -297,7 +313,6 @@ static void real_parser_handler( script_name_len != uri_len) // under IIS they are the same SAPI::die("CGI: illegal call"); } -#endif } else request_info.uri=""; @@ -318,7 +333,18 @@ static void real_parser_handler( /*#endif*/ , true /* status_allowed */); - + + // 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) { const char *config_by_env=getenv(PARSER_CONFIG_ENV_NAME); @@ -349,6 +375,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();