fixed: when signal comes winix properly exits

fixed:   when winix exits the session data were not properly destroyed (memory leak)
         we should set request.session pointer to each session when deleting sessions
         from session_container
         the session data were not properly destroyed when winix checked for 
         outdated sessions (and when it was removing them)
fixed:   performance (memcpy used too often)
         in some places there were reserve method used (on std::wstring/std::string objects)
         especially in AssignString() method and TextStream<> object
         if we add a new string we should check the new size
         and only call reserve() if the new size will be greater than existing one
         (plus some constant)
changed: fcgi objects moved to App class (from Request)
         now we use thread safe methods (e.g. FCGX_Accept_r)
added:   log_plugin_call option to the config
         default: false
         when true winix log when a plugin function is called
added:   winix parameter 'nostat' for not calculating statistics
         (useful when making performance tests)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@680 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-11-23 21:52:25 +00:00
parent 515d4bab0d
commit 518281e101
39 changed files with 483 additions and 339 deletions

View File

@@ -11,6 +11,9 @@
#include <ctime>
#include <signal.h>
#include <iostream>
#include <sys/param.h>
#include <cstdio>
#include <fetch.h>
#include "core/log.h"
#include "core/app.h"
@@ -29,17 +32,28 @@ Plugin plugin;
App app;
static std::string url_to_fetch_on_exit;
void fetch_page_on_exit()
{
// stupid trick to break FCGX_Accept_r() function
// even with FCGX_InitRequest(..., ..., FCGI_FAIL_ACCEPT_ON_INTR) the FCGX_Accept_r
// doesn't want to break on a signal
// so we request one page from the server for exiting from FCGX_Accept_r
FILE * f = fetchGetURL(url_to_fetch_on_exit.c_str(), "");
if( f )
fclose(f);
}
void signal_term(int)
{
plugin.Call(WINIX_CLOSE);
app.Close();
log.PutDate(log1);
log << "winix stopped" << logend << logsave;
// !! sprawdzic czemu ta flaga zatrzymania nie dzialala
// i sprobowac pozbyc sie tego exita tutaj
exit(0);
FCGX_ShutdownPending();
app.WasStopSignal();
fetch_page_on_exit();
}
@@ -86,6 +100,11 @@ int main(int argv, char ** argc)
log.Init(app.config.log_level, app.config.log_file, app.config.log_stdout, app.config.log_request);
nlog.Init(app.config.log_level, app.config.log_notify_file, false, 1);
log << log3 << "-- preparing to start winix --" << logend << logsavenow;
if( !app.InitFCGI() )
return false; // !! dodac logsave do logow
if( !app.DropPrivileges() )
return 3;
@@ -108,6 +127,26 @@ int main(int argv, char ** argc)
app.notify.ReadTemplates(); // wrzucic do notify.Init() ?
// ----
/*
struct sigaction act, old_act;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = signal_term;
sigaction(SIGINT, &act, &old_act);
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = signal_term;
sigaction(SIGTERM, &act, &old_act);
*/
// ----
Ezc::WideToUTF8(app.config.base_url, url_to_fetch_on_exit);
signal(SIGTERM, signal_term);
signal(SIGINT, signal_term);
@@ -120,12 +159,13 @@ int main(int argv, char ** argc)
//app.db.CheckAllUrlSubject();
app.Start();
plugin.Call(WINIX_CLOSE);
app.Close();
log.PutDate(log1);
log << "winix stopped" << logend << logsave;
log << "winix stopped" << logend << logsavenow;
return 0;
}