summaryrefslogtreecommitdiffstats
path: root/src/Daemon/Daemon.cpp
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-06-24 10:27:09 +0200
committerZdenek Prikryl <zprikryl@redhat.com>2009-06-24 10:27:09 +0200
commitce53f0f1f936ae0fad65aa5765cbbe021dfa9359 (patch)
tree9822aff1dd82e660a27e6f92b087db8044a37c4a /src/Daemon/Daemon.cpp
parent44b4926781e2e8751488f3ae18614aa1e63e1138 (diff)
downloadabrt-ce53f0f1f936ae0fad65aa5765cbbe021dfa9359.tar.gz
abrt-ce53f0f1f936ae0fad65aa5765cbbe021dfa9359.tar.xz
abrt-ce53f0f1f936ae0fad65aa5765cbbe021dfa9359.zip
proper way how to daemonize
Diffstat (limited to 'src/Daemon/Daemon.cpp')
-rw-r--r--src/Daemon/Daemon.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp
index a404e809..94f5e666 100644
--- a/src/Daemon/Daemon.cpp
+++ b/src/Daemon/Daemon.cpp
@@ -33,7 +33,7 @@ void terminate(int signal)
void print_help()
{
-
+
}
int main(int argc, char** argv)
@@ -44,7 +44,6 @@ int main(int argc, char** argv)
signal(SIGINT, terminate);
try
{
- g_pCrashWatcher = new CCrashWatcher(DEBUG_DUMPS_DIR);
if (argc > 1)
{
@@ -55,12 +54,26 @@ int main(int argc, char** argv)
}
if(daemonize)
{
- g_pCrashWatcher->Daemonize();
- }
- else
- {
- g_pCrashWatcher->Run();
+ // forking to background
+ pid_t pid = fork();
+ if (pid < 0)
+ {
+ throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Daemonize(): Fork error");
+ }
+ /* parent exits */
+ if (pid > 0) _exit(0);
+ /* child (daemon) continues */
+ pid_t sid = setsid();
+ if(sid == -1)
+ {
+ throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Daemonize(): setsid failed");
+ }
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
}
+ g_pCrashWatcher = new CCrashWatcher(DEBUG_DUMPS_DIR);
+ g_pCrashWatcher->Run();
}
catch(CABRTException& e)
{