/* * This file is a part of CMSLU -- Content Management System like Unix * and is not publicly distributed * * Copyright (c) 2008-2009, Tomasz Sowa * All rights reserved. * */ #include #include #include #include #include "requestcontroller.h" #include "data.h" #include "log.h" #include "request.h" #include "db.h" #include "config.h" // singletons // first 'data' then 'log' then 'request' Data data; Log log; Request request; Db db; Config config; RequestController req_controller; void signal_term(int) { log << log1 << "cmslu stopped" << logend; exit(0); } void signal_hup(int) { log << log1 << "SIGHUP received" << logend; data.signal_hup = true; config.ReadConfig(false); /* errors not to stdout */ } void print_syntax() { std::cout << "Syntax:" << std::endl; std::cout << " cmslu.fcgi config_file" << std::endl; } int main(int argv, char ** argc) { std::srand(std::time(0)); if( argv != 2 ) { print_syntax(); return 1; } data.config_file = argc[1]; if( !config.ReadConfig(true) ) /* errors to stdout */ return 2; // closing descriptors only at the beginning // !! temporary we do not close standard output for errors // client postgresql uses it for reporting warnings (I don't know why) //close(2); if( !data.log_stdout ) { close(1); data.stdout_is_closed = true; } signal(SIGTERM, signal_term); signal(SIGINT, signal_term); signal(SIGHUP, signal_hup); while( true ) { log.Init(data.log_level, data.log_file, data.log_stdout); db.Init(data.db_database, data.db_user, data.db_pass); request.Init(); if( !req_controller.Init() ) return 1; //log << log2 << "checking for table consistency:" << logend; // !! zrobic wyjatek dla root //db.CheckAllUrlSubject(); log << log1 << "cmslu started" << logend; req_controller.Loop(); if( data.signal_hup ) data.signal_hup = false; } return 0; }