/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2008-2011, Tomasz Sowa * All rights reserved. * */ #include #include #include #include #include "core/log.h" #include "core/app.h" #include "core/plugin.h" Log log; Log nlog; // notify log (used by a notification thread) Plugin plugin; /* application object */ App app; void print_syntax() { std::cout << "Syntax:" << std::endl; std::cout << " winix config_file" << std::endl; } int main(int argv, char ** argc) { std::srand(std::time(0)); if( argv != 2 ) { print_syntax(); return 1; } app.system.system_start = time(0); app.config.config_file = argc[1]; if( !app.config.ReadConfig(true, false) ) /* errors to stdout, stdout in not closed */ return 2; if( app.stdout_is_closed || app.config.demonize ) app.config.log_stdout = false; // 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( !app.config.log_stdout ) { close(1); app.stdout_is_closed = true; } log.Init(app.config.log_level, app.config.log_save_each_line, app.config.log_file, app.config.log_stdout, app.config.log_request); nlog.Init(app.config.log_level, true, app.config.log_notify_file, false, 1); log << log3 << "-- preparing to start winix --" << logend; if( !app.InitFCGI() ) return false; if( !app.DropPrivileges() ) return 3; app.LogUserGroups(); if( app.config.demonize && !app.Demonize() ) return 4; // app.config.base_server can be changed (stripped from 'http://' or a last slash) // it is done when the config is read log << log3 << "base_server: " << app.config.base_server << logend; // load plugins before loading sessions - session_manager.LoadSessions() // because some of the plugins can init its own sessions dates plugin.LoadPlugins(app.config.plugins_dir, app.config.plugin_file); // app.Init() starts other threads as well (they will be waiting on the lock) if( !app.Init() ) return 1; log.PutDate(log1); log << "winix started" << logend << logsave; app.StartThreads(); // now we have more threads, we should use Lock() and Unlock() // main loop app.Start(); app.Lock(); plugin.Call(WINIX_CLOSE); app.Close(); app.Unlock(); app.WaitForThreads(); // now all others threads are terminated log.PutDate(log1); log << "winix stopped" << logend << logsave; return 0; }