Files
winix/main/main.cpp
Tomasz Sowa 18ecd46a01 changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added:   DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
         it reads binary (bytea) data
added:   DbTextStream can handle 'bool' types now
         (is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
         with RSA
         currently we have following hashes:
         md4, md5, sha1, sha224, sha256, sha384, sha512
         we are using openssl to manage them
         (look at config options for more info)
changed: winix version to 0.4.7         
added:   class Run - you can run any program from os and send a buffer to its standard input
         and read what the program put on its standard output
added:   class Crypt (in System) - calculating hashes, and crypting/decrypting




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 21:22:08 +00:00

150 lines
2.7 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sys/param.h>
#include <fcntl.h>
#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;
}
void CreateNewDescriptor(int des_dst, int flags)
{
int descriptor;
descriptor = open("/dev/null", flags | O_NOCTTY);
if( descriptor != -1 )
{
dup2(descriptor, des_dst);
if( descriptor != des_dst )
close(descriptor);
}
}
void CloseDescriptors()
{
close(0);
close(1);
close(2);
app.stdout_is_closed = true;
CreateNewDescriptor(0, O_RDONLY);
CreateNewDescriptor(1, O_WRONLY);
CreateNewDescriptor(2, O_WRONLY);
}
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;
if( !app.config.log_stdout )
CloseDescriptors();
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;
}