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:
97
core/app.cpp
97
core/app.cpp
@@ -16,15 +16,17 @@
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
#include "functions/functions.h"
|
||||
#include "ezc.h"
|
||||
#include "utf8.h"
|
||||
|
||||
|
||||
|
||||
|
||||
App::App()
|
||||
{
|
||||
was_stop_signal = false;
|
||||
stdout_is_closed = false;
|
||||
last_sessions_save = std::time(0);
|
||||
fcgi_socket = -1;
|
||||
|
||||
db.SetConn(db_conn);
|
||||
|
||||
@@ -73,30 +75,27 @@ App::App()
|
||||
|
||||
|
||||
|
||||
bool App::CreateFCGISocket()
|
||||
bool App::InitFCGI()
|
||||
{
|
||||
const char * sock = config.fcgi_socket.c_str();
|
||||
|
||||
unlink(sock);
|
||||
|
||||
fcgi_socket = FCGX_OpenSocket(sock, 100); // !! dodac 100 do konfiga
|
||||
|
||||
|
||||
int s = FCGX_OpenSocket(sock, 100);
|
||||
|
||||
if( s < 0 )
|
||||
if( fcgi_socket < 0 )
|
||||
{
|
||||
log << log1 << "An error during creating a socket" << logend;
|
||||
log << log1 << "App: An error during creating a fcgi socket" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
log << log3 << "App: FastCGI socket number: " << fcgi_socket << logend;
|
||||
chmod(sock, config.fcgi_socket_chmod);
|
||||
|
||||
passwd * pw = getpwnam(config.fcgi_socket_user.c_str());
|
||||
|
||||
if( !pw )
|
||||
{
|
||||
log << log1 << "There is no user: " << config.fcgi_socket_user << logend;
|
||||
log << log1 << "App: there is no user: " << config.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -104,32 +103,23 @@ bool App::CreateFCGISocket()
|
||||
|
||||
if( !gr )
|
||||
{
|
||||
log << log1 << "There is no group: " << config.fcgi_socket_group << logend;
|
||||
log << log1 << "App: there is no group: " << config.fcgi_socket_group << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
chown(sock, pw->pw_uid, gr->gr_gid);
|
||||
|
||||
|
||||
if( setuid(pw->pw_uid) < 0 )
|
||||
if( FCGX_Init() != 0 )
|
||||
{
|
||||
log << log1 << "I can't change the user into: " << config.fcgi_socket_user << logend;
|
||||
log << log1 << "App: FCGX_Init fails" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if( setgid(gr->gr_gid) < 0 )
|
||||
if( FCGX_InitRequest(&fcgi_request, fcgi_socket, FCGI_FAIL_ACCEPT_ON_INTR) != 0 )
|
||||
{
|
||||
int e = errno;
|
||||
|
||||
log << log1 << "I can't change the group into: " << config.fcgi_socket_group << " " << gr->gr_gid << logend;
|
||||
log << log1 << "errno: " << e << logend;
|
||||
log << log1 << "App: FCGX_InitRequest fails" << logend;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
dup2(s, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -142,9 +132,6 @@ bool App::Init()
|
||||
db_conn.WaitForConnection();
|
||||
db.LogQueries(config.log_db_query);
|
||||
|
||||
if( !CreateFCGISocket() )
|
||||
return false; // !! dodac logsave do logow
|
||||
|
||||
request.Clear();
|
||||
compress.Init();
|
||||
system.Init();
|
||||
@@ -178,7 +165,8 @@ return true;
|
||||
void App::Close()
|
||||
{
|
||||
session_manager.SaveSessions();
|
||||
session_manager.DeleteAllPluginsData();
|
||||
session_manager.DeleteSessions();
|
||||
request.Clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -265,8 +253,11 @@ void App::ProcessRequest()
|
||||
|
||||
void App::Start()
|
||||
{
|
||||
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
|
||||
while( !was_stop_signal && FCGX_Accept_r(&fcgi_request) == 0 )
|
||||
{
|
||||
if( was_stop_signal )
|
||||
break;
|
||||
|
||||
system.load_avg.StartRequest();
|
||||
log << log2 << config.log_delimiter << logend;
|
||||
|
||||
@@ -383,7 +374,7 @@ void App::Make()
|
||||
// !! dodac inne informacje (get, post, itp)
|
||||
// jesli jest debug_info wlaczone to nie robic przekierowan
|
||||
request.PrintGetTab();
|
||||
request.PrintEnv();
|
||||
//request.PrintEnv(); // !! PrintEnv() mozna przeniesc tutaj (do klasy App)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +406,7 @@ void App::ReadRequest()
|
||||
|
||||
void App::SetEnv(const char * & env, const char * name)
|
||||
{
|
||||
const char * v = FCGX_GetParam(name, request.env);
|
||||
const char * v = FCGX_GetParam(name, fcgi_request.envp);
|
||||
|
||||
if( v )
|
||||
env = v;
|
||||
@@ -430,7 +421,7 @@ void App::ReadEnvVariables()
|
||||
// we store that values because FCGX_GetParam has O(n) complexity
|
||||
// with this variables (env_*) we have O(1)
|
||||
|
||||
SetEnv(request.env_request_method, "REQUEST_METHOD");
|
||||
SetEnv(request.env_request_method, "REQUEST_METHOD"); // !! mozna nie uzywac tego, teraz mamy w strukturze fcgi_request
|
||||
SetEnv(request.env_request_uri, "REQUEST_URI");
|
||||
SetEnv(request.env_http_cookie, "HTTP_COOKIE");
|
||||
SetEnv(request.env_remote_addr, "REMOTE_ADDR");
|
||||
@@ -497,12 +488,12 @@ void App::ReadGetPostVars()
|
||||
// !! dodac metode UTF8 do post_multi_parsera
|
||||
// (narazie bierze bezposrednio z konfigu)
|
||||
// w ogole wywalic zaleznosc od konfiga
|
||||
post_multi_parser.Parse(request.in, request.post_tab, request.post_file_tab);
|
||||
post_multi_parser.Parse(fcgi_request.in, request.post_tab, request.post_file_tab);
|
||||
}
|
||||
else
|
||||
{
|
||||
post_parser.UTF8(config.utf8);
|
||||
post_parser.Parse(request.in, request.post_tab);
|
||||
post_parser.Parse(fcgi_request.in, request.post_tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -562,13 +553,13 @@ void App::SendHeaders(bool compressing, Header header)
|
||||
PrepareSessionCookie();
|
||||
|
||||
if( request.send_as_attachment )
|
||||
FCGX_PutS("Content-Disposition: attachment\r\n", request.out);
|
||||
FCGX_PutS("Content-Disposition: attachment\r\n", fcgi_request.out);
|
||||
|
||||
if( !request.redirect_to.empty() )
|
||||
{
|
||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", request.out);
|
||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", fcgi_request.out);
|
||||
AssignString(request.redirect_to, request.aredirect_to);
|
||||
FCGX_FPrintF(request.out, "Location: %s\r\n", request.aredirect_to.c_str());
|
||||
FCGX_FPrintF(fcgi_request.out, "Location: %s\r\n", request.aredirect_to.c_str());
|
||||
log << log2 << "Redirect to: " << request.redirect_to << logend;
|
||||
}
|
||||
else
|
||||
@@ -578,9 +569,9 @@ void App::SendHeaders(bool compressing, Header header)
|
||||
|
||||
AssignString(config.http_header_send_file, temp);
|
||||
AssignString(request.x_sendfile, temp2);
|
||||
FCGX_FPrintF(request.out, "%s: %s\r\n", temp.c_str(), temp2.c_str());
|
||||
FCGX_FPrintF(fcgi_request.out, "%s: %s\r\n", temp.c_str(), temp2.c_str());
|
||||
|
||||
FCGX_PutS("Status: 200 OK\r\n", request.out);
|
||||
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
|
||||
log << log2 << "Sending file: " << request.x_sendfile << logend;
|
||||
}
|
||||
else
|
||||
@@ -588,30 +579,30 @@ void App::SendHeaders(bool compressing, Header header)
|
||||
switch( header )
|
||||
{
|
||||
case h_404:
|
||||
FCGX_PutS("Status: 404 Not Found\r\n", request.out);
|
||||
FCGX_PutS("Content-Type: text/html\r\n", request.out);
|
||||
FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out);
|
||||
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
|
||||
log << log2 << "Request: response: 404 Not Found" << logend;
|
||||
break;
|
||||
|
||||
case h_403:
|
||||
FCGX_PutS("Status: 403 Forbidden\r\n", request.out);
|
||||
FCGX_PutS("Content-Type: text/html\r\n", request.out);
|
||||
FCGX_PutS("Status: 403 Forbidden\r\n", fcgi_request.out);
|
||||
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
|
||||
log << log2 << "Request: response: 403 Forbidden" << logend;
|
||||
break;
|
||||
|
||||
default:
|
||||
FCGX_PutS("Status: 200 OK\r\n", request.out);
|
||||
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
|
||||
|
||||
if( request.role != Request::authorizer )
|
||||
FCGX_PutS("Content-Type: text/html\r\n", request.out);
|
||||
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
|
||||
}
|
||||
}
|
||||
|
||||
if( compressing )
|
||||
FCGX_PutS("Content-Encoding: deflate\r\n", request.out);
|
||||
FCGX_PutS("Content-Encoding: deflate\r\n", fcgi_request.out);
|
||||
|
||||
FCGX_PutS(request.headers.CStr(), request.out);
|
||||
FCGX_PutS("\r\n", request.out);
|
||||
FCGX_PutS(request.headers.CStr(), fcgi_request.out);
|
||||
FCGX_PutS("\r\n", fcgi_request.out);
|
||||
}
|
||||
|
||||
|
||||
@@ -656,9 +647,9 @@ void App::FilterCompressSend(bool compressing, const std::wstring & source_ref)
|
||||
Ezc::WideToUTF8(*source, temp);
|
||||
|
||||
if( compressing )
|
||||
compress.CompressAndPut(temp.c_str(), temp.length(), request.out);
|
||||
compress.CompressAndPut(temp.c_str(), temp.length(), fcgi_request.out);
|
||||
else
|
||||
FCGX_PutS(temp.c_str(), request.out);
|
||||
FCGX_PutS(temp.c_str(), fcgi_request.out);
|
||||
}
|
||||
|
||||
|
||||
@@ -971,3 +962,9 @@ bool App::Demonize()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void App::WasStopSignal()
|
||||
{
|
||||
was_stop_signal = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user