diff options
author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-06-23 13:53:05 +0200 |
---|---|---|
committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-06-23 13:53:05 +0200 |
commit | 1b5ef9199a0a35b7c6e0bc4e17285e2a890456c7 (patch) | |
tree | eac89f72f281a1b7e46fee69404d037d0b1a3c12 | |
parent | 7342d3896446deaf89ab5582da81457571e48fe6 (diff) | |
download | abrt-1b5ef9199a0a35b7c6e0bc4e17285e2a890456c7.tar.gz abrt-1b5ef9199a0a35b7c6e0bc4e17285e2a890456c7.tar.xz abrt-1b5ef9199a0a35b7c6e0bc4e17285e2a890456c7.zip |
Added pidfile support in daemon (C hook should work now)
-rw-r--r-- | src/Daemon/CrashWatcher.cpp | 38 | ||||
-rw-r--r-- | src/Daemon/CrashWatcher.h | 2 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 2670ce83..ef31ad5f 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -34,6 +34,7 @@ #include "ABRTException.h" #define VAR_RUN_LOCK_FILE VAR_RUN"/abrt.lock" +#define VAR_RUN_PIDFILE VAR_RUN"/abrt.pid" /* just a helper function template< class T > @@ -414,6 +415,10 @@ CCrashWatcher::~CCrashWatcher() delete m_pMW; delete m_pSettings; delete m_pCommLayerInner; + /* delete pid file */ + unlink(VAR_RUN_PIDFILE); + /* delete lock file */ + unlink(VAR_RUN_LOCK_FILE); } void CCrashWatcher::FindNewDumps(const std::string& pPath) { @@ -484,6 +489,32 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath) } } } +void CCrashWatcher::CreatePidFile() +{ + int fd; + + /* JIC */ + unlink(VAR_RUN_PIDFILE); + + /* open the pidfile */ + fd = open(VAR_RUN_PIDFILE, O_WRONLY|O_CREAT|O_EXCL, 0644); + if (fd >= 0) { + FILE *f; + + /* write our pid to it */ + f = fdopen(fd, "w"); + if (f != NULL) { + fprintf(f, "%d\n", getpid()); + fclose(f); + /* leave the fd open */ + return; + } + close(fd); + } + + /* something went wrong */ + CABRTException(EXCEP_FATAL, "CCrashWatcher::CreatePidFile(): can not open pid file"); +} void CCrashWatcher::Lock() { @@ -543,7 +574,8 @@ void CCrashWatcher::GStartWatch() void CCrashWatcher::Daemonize() { - + Lock(); + CreatePidFile(); Debug("Daemonize..."); // forking to background pid_t pid = fork(); @@ -562,14 +594,14 @@ void CCrashWatcher::Daemonize() close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); - Lock(); GStartWatch(); } void CCrashWatcher::Run() { - Debug("Runnig..."); Lock(); + CreatePidFile(); + Debug("Runnig..."); GStartWatch(); } diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index 98ad9156..a181f38a 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -77,10 +77,12 @@ class CCrashWatcher void StartWatch(); void GStartWatch(); + void CreatePidFile(); void Lock(); void SetUpMW(); void SetUpCron(); /* finds dumps created when daemon wasn't running */ + // FIXME: how to catch abrt itself without this? void FindNewDumps(const std::string& pPath); double GetDirSize(const std::string &pPath); |