now winix can demonize itself
parameter in the config: demonize (default: true) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@669 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
9c34cb5862
commit
c6473f20dc
30
core/app.cpp
30
core/app.cpp
|
@ -927,3 +927,33 @@ bool App::DropPrivileges()
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::Demonize()
|
||||
{
|
||||
// in linux fork() should be used twice
|
||||
|
||||
int pid = fork();
|
||||
|
||||
if( pid == -1 )
|
||||
{
|
||||
log << log1 << "App: I can't demonize myself (fork problem)" << logend << logsave;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( pid != 0 )
|
||||
{
|
||||
// parent
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// child
|
||||
if( setsid() == -1 )
|
||||
{
|
||||
log << log1 << "App: I can't demonize myself (setsid problem)" << logend << logsave;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
void Close();
|
||||
bool DropPrivileges();
|
||||
void LogUserGroups();
|
||||
|
||||
bool Demonize();
|
||||
|
||||
// configuration read from a config file
|
||||
Config config;
|
||||
|
|
|
@ -89,6 +89,8 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
|||
|
||||
void Config::AssignValues(bool stdout_is_closed)
|
||||
{
|
||||
demonize = Bool("demonize", true);
|
||||
|
||||
user = Text("user");
|
||||
group = Text("group");
|
||||
additional_groups = Bool("additional_groups", true);
|
||||
|
|
|
@ -21,9 +21,14 @@ class Config
|
|||
{
|
||||
public:
|
||||
|
||||
// name of the config file (full path can be)
|
||||
// name of the config file
|
||||
// this is the parameter passed to winix programm
|
||||
std::string config_file;
|
||||
|
||||
// start as a demon (in the background)
|
||||
// default: true
|
||||
bool demonize;
|
||||
|
||||
// system user name (to which drop privileges)
|
||||
// used only if winix is started as the root
|
||||
std::string user;
|
||||
|
@ -47,6 +52,8 @@ public:
|
|||
int log_level;
|
||||
|
||||
// logging to stdout too
|
||||
// only if demonize is 'false'
|
||||
// default: false
|
||||
bool log_stdout;
|
||||
|
||||
// how many requests should be logged in the same time
|
||||
|
|
|
@ -68,7 +68,7 @@ int main(int argv, char ** argc)
|
|||
if( !app.config.ReadConfig(true, false) ) /* errors to stdout, stdout in not closed */
|
||||
return 2;
|
||||
|
||||
if( app.stdout_is_closed )
|
||||
if( app.stdout_is_closed || app.config.demonize )
|
||||
app.config.log_stdout = false;
|
||||
|
||||
// closing descriptors only at the beginning
|
||||
|
@ -90,6 +90,9 @@ int main(int argv, char ** argc)
|
|||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue