summaryrefslogtreecommitdiffstats
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
parent44b4926781e2e8751488f3ae18614aa1e63e1138 (diff)
downloadabrt-ce53f0f1f936ae0fad65aa5765cbbe021dfa9359.tar.gz
abrt-ce53f0f1f936ae0fad65aa5765cbbe021dfa9359.tar.xz
abrt-ce53f0f1f936ae0fad65aa5765cbbe021dfa9359.zip
proper way how to daemonize
-rw-r--r--src/Daemon/CrashWatcher.cpp29
-rw-r--r--src/Daemon/CrashWatcher.h3
-rw-r--r--src/Daemon/Daemon.cpp27
3 files changed, 21 insertions, 38 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
index 674a6950..f13d8427 100644
--- a/src/Daemon/CrashWatcher.cpp
+++ b/src/Daemon/CrashWatcher.cpp
@@ -571,38 +571,11 @@ void CCrashWatcher::GStartWatch()
g_main_run (m_pMainloop);
}
-
-void CCrashWatcher::Daemonize()
-{
- Lock();
- Debug("Daemonize...");
- // 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);
- /* we need a pid file for the child process */
- CreatePidFile();
- GStartWatch();
-}
-
void CCrashWatcher::Run()
{
+ Debug("Runnig...");
Lock();
CreatePidFile();
- Debug("Runnig...");
GStartWatch();
}
diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h
index a181f38a..e5124789 100644
--- a/src/Daemon/CrashWatcher.h
+++ b/src/Daemon/CrashWatcher.h
@@ -100,9 +100,6 @@ class CCrashWatcher
//CCrashWatcher(const std::string& pPath,DBus::Connection &connection);
CCrashWatcher(const std::string& pPath);
virtual ~CCrashWatcher();
- //run as daemon
- void Daemonize();
- //don't go background - for debug
void Run();
/* methods exported on dbus */
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)
{