import the first version of cmslu
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@460 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
137
core/requestcontroller.cpp
Executable file
137
core/requestcontroller.cpp
Executable file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "requestcontroller.h"
|
||||
|
||||
|
||||
|
||||
RequestController::RequestController()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool RequestController::Init()
|
||||
{
|
||||
const char * sock = data.fcgi_socket.c_str();
|
||||
|
||||
unlink(sock);
|
||||
|
||||
|
||||
|
||||
int s = FCGX_OpenSocket(sock, 10);
|
||||
|
||||
if( s < 0 )
|
||||
{
|
||||
log << log1 << "An error during creating a socket" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
chmod(sock, data.fcgi_socket_chmod);
|
||||
|
||||
passwd * pw = getpwnam(data.fcgi_socket_user.c_str());
|
||||
|
||||
if( !pw )
|
||||
{
|
||||
log << log1 << "There is no user: " << data.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
group * gr = getgrnam(data.fcgi_socket_group.c_str());
|
||||
|
||||
if( !gr )
|
||||
{
|
||||
log << log1 << "There is no group: " << data.fcgi_socket_group << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
chown(sock, pw->pw_uid, gr->gr_gid);
|
||||
|
||||
|
||||
|
||||
if( setuid(pw->pw_uid) < 0 )
|
||||
{
|
||||
log << log1 << "I can't change the user into: " << data.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if( setgid(gr->gr_gid) < 0 )
|
||||
{
|
||||
int e = errno;
|
||||
|
||||
log << log1 << "I can't change the group into: " << data.fcgi_socket_group << " " << gr->gr_gid << logend;
|
||||
log << log1 << "errno: " << e << logend;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
dup2(s, 0);
|
||||
|
||||
if( !data.log_stdout )
|
||||
close(1);
|
||||
|
||||
close(2);
|
||||
|
||||
|
||||
//
|
||||
|
||||
data.dir.ReadDirs();
|
||||
|
||||
//
|
||||
|
||||
if( !content.Init() )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RequestController::Loop()
|
||||
{
|
||||
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
|
||||
{
|
||||
log << log2 << "start request" << logend;
|
||||
|
||||
try
|
||||
{
|
||||
request.Clear();
|
||||
request.Read();
|
||||
|
||||
session_manager.SetSession(); // setting request.session as well
|
||||
request.session->CheckTimers();
|
||||
|
||||
content.Make();
|
||||
request.SendAll();
|
||||
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
log << log1 << "uncaught std exception: " << e.what() << logend;
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "uncaught exception: Error: " << e << logend;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
log << log1 << "uncaught exception" << logend;
|
||||
}
|
||||
|
||||
|
||||
log << log2 << "end request" << logend;
|
||||
log << log2 << "---------------------------------------------------------------------------------" << logend;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user