From 803e4ed1681c930c5845f838ee9c6718ffb8536e Mon Sep 17 00:00:00 2001 From: Matt Lebofsky Date: Tue, 24 Aug 2004 19:57:15 +0000 Subject: [PATCH] added counter/timeout loop svn path=/trunk/boinc/; revision=4102 --- sched/main.C | 108 ++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/sched/main.C b/sched/main.C index 829e6638bd..cf0eb365aa 100644 --- a/sched/main.C +++ b/sched/main.C @@ -50,6 +50,7 @@ using namespace std; #endif #define DEBUG_LEVEL 999 +#define MAX_FCGI_COUNT 20 void get_log_path(char* p) { char buf[256]; @@ -69,8 +70,7 @@ key_t sema_key; int g_pid; void send_message(char* msg, int delay) { - fprintf( - stdout, + printf( "Content-type: text/plain\n\n" "\n" " %s\n" @@ -173,59 +173,69 @@ int main() { g_pid = getpid(); #ifdef _USING_FCGI_ - while(FCGI_Accept() >= 0) { - counter++; + while(FCGI_Accept() >= 0 && counter < MAX_FCGI_COUNT) { + counter++; #endif - if (project_stopped) { - send_message("Project is temporarily shut down for maintenance", 3600); - goto done; + if (project_stopped) { + send_message("Project is temporarily shut down for maintenance", 3600); + goto done; + } + fprintf(stdout,"Content-type: text/plain\n\n"); + if (use_files) { + // the code below is convoluted because, + // instead of going from stdin to stdout directly, + // we go via a pair of disk files + // (this makes it easy to save the input, + // and to know the length of the output). + // + sprintf(req_path, "%s%d_%u", REQ_FILE_PREFIX, g_pid, counter); + sprintf(reply_path, "%s%d_%u", REPLY_FILE_PREFIX, g_pid, counter); + fout = fopen(req_path, "w"); + if (!fout) { + log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write request file\n"); + exit(1); } - fprintf(stdout,"Content-type: text/plain\n\n"); - if (use_files) { - // the code below is convoluted because, - // instead of going from stdin to stdout directly, - // we go via a pair of disk files - // (this makes it easy to save the input, - // and to know the length of the output). - // - sprintf(req_path, "%s%d_%u", REQ_FILE_PREFIX, g_pid, counter); - sprintf(reply_path, "%s%d_%u", REPLY_FILE_PREFIX, g_pid, counter); - fout = fopen(req_path, "w"); - if (!fout) { - log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write request file\n"); - exit(1); - } - copy_stream(stdin, fout); - fclose(fout); - fin = fopen(req_path, "r"); - if (!fin) { - log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read request file\n"); - exit(1); - } - fout = fopen(reply_path, "w"); - if (!fout) { - log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write reply file\n"); - exit(1); - } - handle_request(fin, fout, *ssp, code_sign_key); - fclose(fin); - fclose(fout); - fin = fopen(reply_path, "r"); - if (!fin) { - log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read reply file\n"); - exit(1); - } - copy_stream(fin, stdout); - fclose(fin); - //unlink(req_path); - //unlink(reply_path); - } else { - handle_request(stdin, stdout, *ssp, code_sign_key); + copy_stream(stdin, fout); + fclose(fout); + fin = fopen(req_path, "r"); + if (!fin) { + log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read request file\n"); + exit(1); } + fout = fopen(reply_path, "w"); + if (!fout) { + log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write reply file\n"); + exit(1); + } + handle_request(fin, fout, *ssp, code_sign_key); + fclose(fin); + fclose(fout); + fin = fopen(reply_path, "r"); + if (!fin) { + log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read reply file\n"); + exit(1); + } + copy_stream(fin, stdout); + fclose(fin); + //unlink(req_path); + //unlink(reply_path); + } else { + handle_request(stdin, stdout, *ssp, code_sign_key); + } done: #ifdef _USING_FCGI_ - continue; + fprintf(stderr, "FCGI: counter: %d\n", counter); + continue; } + if (counter == MAX_FCGI_COUNT) { + fprintf(stderr, "FCGI: counter passed MAX_FCGI_COUNT - exiting..\n"); + } + else { + fprintf(stderr, "FCGI: FCGI_Accept failed - exiting..\n"); + } + // when exiting, write headers back to apache so it won't complain + // about "incomplete headers" + fprintf(stdout,"Content-type: text/plain\n\n"); #endif if (db_opened) { boinc_db.close();