2008-12-10 05:42:49 +01:00
|
|
|
/*
|
|
|
|
* 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 <cstdlib>
|
|
|
|
#include <ctime>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "requestcontroller.h"
|
|
|
|
#include "data.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "request.h"
|
|
|
|
#include "db.h"
|
2008-12-11 03:46:16 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
// singletons
|
|
|
|
// first 'data' then 'log' then 'request'
|
|
|
|
Data data;
|
|
|
|
Log log;
|
|
|
|
Request request;
|
|
|
|
Db db;
|
2008-12-11 03:46:16 +01:00
|
|
|
Config config;
|
2009-01-31 07:53:36 +01:00
|
|
|
RequestController req_controller;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void signal_term(int)
|
|
|
|
{
|
2008-12-11 03:46:16 +01:00
|
|
|
log << log1 << "cmslu stopped" << logend;
|
2008-12-10 05:42:49 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
void signal_hup(int)
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2009-01-14 21:11:12 +01:00
|
|
|
log << log1 << "SIGHUP received" << logend;
|
2008-12-11 03:46:16 +01:00
|
|
|
data.signal_hup = true;
|
|
|
|
config.ReadConfig(false); /* errors not to stdout */
|
|
|
|
}
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
void print_syntax()
|
|
|
|
{
|
|
|
|
std::cout << "Syntax:" << std::endl;
|
|
|
|
std::cout << " cmslu.fcgi config_file" << std::endl;
|
|
|
|
}
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
int main(int argv, char ** argc)
|
|
|
|
{
|
|
|
|
|
2009-01-26 21:49:28 +01:00
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
std::srand(std::time(0));
|
|
|
|
|
|
|
|
if( argv != 2 )
|
|
|
|
{
|
|
|
|
print_syntax();
|
2008-12-10 05:42:49 +01:00
|
|
|
return 1;
|
2008-12-11 03:46:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
data.config_file = argc[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !config.ReadConfig(true) ) /* errors to stdout */
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
|
|
|
|
// closing descriptors only at the beginning
|
2009-01-26 21:49:28 +01:00
|
|
|
// !! temporary we do not close standard output for errors
|
|
|
|
// client postgresql uses it for reporting warnings (I don't know why)
|
|
|
|
//close(2);
|
2008-12-11 03:46:16 +01:00
|
|
|
|
|
|
|
if( !data.log_stdout )
|
|
|
|
{
|
|
|
|
close(1);
|
|
|
|
data.stdout_is_closed = true;
|
|
|
|
}
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2009-01-26 21:49:28 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
signal(SIGTERM, signal_term);
|
2008-12-11 03:46:16 +01:00
|
|
|
signal(SIGINT, signal_term);
|
|
|
|
signal(SIGHUP, signal_hup);
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
log.Init(data.log_level, data.log_file, data.log_stdout);
|
|
|
|
db.Init(data.db_database, data.db_user, data.db_pass);
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
if( !req_controller.Init() )
|
|
|
|
return 1;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2009-01-26 21:49:28 +01:00
|
|
|
//log << log2 << "checking for table consistency:" << logend;
|
2008-12-30 02:05:03 +01:00
|
|
|
// !! zrobic wyjatek dla root
|
|
|
|
//db.CheckAllUrlSubject();
|
2008-12-11 03:46:16 +01:00
|
|
|
|
|
|
|
log << log1 << "cmslu started" << logend;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
req_controller.Loop();
|
|
|
|
|
|
|
|
if( data.signal_hup )
|
|
|
|
data.signal_hup = false;
|
|
|
|
}
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|