--- parser3/src/targets/cgi/parser3.C 2020/12/31 19:48:47 1.342 +++ parser3/src/targets/cgi/parser3.C 2022/01/26 17:04:46 1.347 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.342 2020/12/31 19:48:47 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.347 2022/01/26 17:04:46 moko Exp $"; #include "pa_config_includes.h" @@ -50,7 +50,7 @@ static const char* filespec_to_process = static const char* httpd_host_port = 0; // -p option static const char* config_filespec = 0; // -f option or from env or next to the executable if exists static bool mail_received = false; // -m option? [asked to parse incoming message to $mail:received] -static char* parser3_filespec = 0; // argv[0] +static const char* parser3_filespec = 0; // argv[0] static char** argv_extra = NULL; // for error logging @@ -77,7 +77,7 @@ static void pa_log(const char* fmt, va_l if(!opened && filespec_4log) { char beside_config_path[MAX_STRING]; - strncpy(beside_config_path, filespec_4log, MAX_STRING-1); beside_config_path[MAX_STRING-1]=0; + pa_strncpy(beside_config_path, filespec_4log, MAX_STRING); if(!(rsplit(beside_config_path, '/') || rsplit(beside_config_path, '\\'))) { // strip filename // no path, just filename strcpy(beside_config_path, "."); @@ -186,7 +186,7 @@ static void full_disk_path(const char* f || file_name[0] && file_name[1]==':' #endif ){ - strncpy(buf, file_name, buf_size-1); buf[buf_size-1]=0; + pa_strncpy(buf, file_name, buf_size); } else { char cwd[MAX_STRING]; snprintf(buf, buf_size, "%s/%s", getcwd(cwd, MAX_STRING) ? cwd : "", file_name); @@ -378,11 +378,8 @@ static void *connection_thread(void *arg static void httpd_mode() { config_handler(*sapiInfo); - int sock = HTTPD_Server::bind(httpd_host_port); + SOCKET sock = HTTPD_Server::bind(httpd_host_port); -#ifdef SIGCHLD - signal(SIGCHLD, SIG_IGN); -#endif #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif @@ -390,10 +387,12 @@ static void httpd_mode() { while(1){ #ifndef _MSC_VER pid_t pid=1; + if(HTTPD_Server::mode == HTTPD_Server::PARALLEL) + while (waitpid((pid_t)(-1), 0, WNOHANG) > 0); #endif try { HTTPD_Connection connection; - if(!connection.accept(sock, 5)) + if(!connection.accept(sock, 500)) continue; switch (HTTPD_Server::mode) { @@ -401,7 +400,7 @@ static void httpd_mode() { #ifdef _MSC_VER if (!GC_CreateThread(0, 0, connection_thread, new HTTPD_Connection(connection), 0, 0)) throw Exception("httpd.fork", 0, "thread creation failed"); - connection.sock = -1; + connection.sock=INVALID_SOCKET; break; #else #ifdef HAVE_TLS @@ -412,7 +411,7 @@ static void httpd_mode() { if(int result=GC_pthread_create(&thread, &attr, connection_thread, new HTTPD_Connection(connection))) throw Exception("httpd.fork", 0, "thread creation failed (%d)", result); - connection.sock=-1; + connection.sock=INVALID_SOCKET; break; #endif case HTTPD_Server::PARALLEL: @@ -600,7 +599,7 @@ int main(int argc, char *argv[]) { log("main: entry"); #endif - parser3_filespec = argv[0]; + parser3_filespec = argc ? argv[0] : "parser3"; umask(2); // were we started as CGI? @@ -626,7 +625,7 @@ int main(int argc, char *argv[]) { char c = carg[k]; switch (c) { case 'h': - usage(argv[0]); + usage(parser3_filespec); break; case 'f': if(optind < argc - 1){ @@ -646,8 +645,8 @@ int main(int argc, char *argv[]) { break; #endif default: - fprintf(stderr, "%s: invalid option '%c'\n", argv[0], c); - usage(argv[0]); + fprintf(stderr, "%s: invalid option '%c'\n", parser3_filespec, c); + usage(parser3_filespec); break; } } @@ -656,16 +655,16 @@ int main(int argc, char *argv[]) { if (optind > argc - 1) { if(!httpd_host_port) { - fprintf(stderr, "%s: file not specified\n", argv[0]); - usage(argv[0]); + fprintf(stderr, "%s: file not specified\n", parser3_filespec); + usage(parser3_filespec); } } else { raw_filespec_to_process=argv[optind]; } if (httpd_host_port && mail_received) { - fprintf(stderr, "%s: -p and -m options should not be used together\n", argv[0]); - usage(argv[0]); + fprintf(stderr, "%s: -p and -m options should not be used together\n", parser3_filespec); + usage(parser3_filespec); } argv_extra=argv + optind;