diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-15 15:12:16 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-15 15:12:16 +0200 |
| commit | 3431b2cee2ad71c0046bcef239ddd30539c202ae (patch) | |
| tree | 85eb6f41b1104ab7cc188f3edd9a03ec38df8ce4 /src | |
| parent | 916a86b4c0bd1297bdb2b98f12927d82910097f8 (diff) | |
| download | abrt-3431b2cee2ad71c0046bcef239ddd30539c202ae.tar.gz abrt-3431b2cee2ad71c0046bcef239ddd30539c202ae.tar.xz abrt-3431b2cee2ad71c0046bcef239ddd30539c202ae.zip | |
Restore /proc/sys/kernel/core_pattern on error exit.
The bug was observed when dbus-abrt.conf is missing.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/Daemon/CrashWatcher.cpp | 67 | ||||
| -rw-r--r-- | src/Daemon/Daemon.cpp | 20 |
2 files changed, 57 insertions, 30 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 9a14967..4513309 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -380,27 +380,38 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath) m_pMainloop = g_main_loop_new(NULL,FALSE); m_pMW = new CMiddleWare(PLUGINS_CONF_DIR,PLUGINS_LIB_DIR); - SetUpMW(); - SetUpCron(); - FindNewDumps(pPath); + + try + { + SetUpMW(); + SetUpCron(); + FindNewDumps(pPath); #ifdef ENABLE_DBUS - m_pCommLayer = new CCommLayerServerDBus(); + m_pCommLayer = new CCommLayerServerDBus(); #elif ENABLE_SOCKET - m_pCommLayer = new CCommLayerServerSocket(); + m_pCommLayer = new CCommLayerServerSocket(); #endif -// m_pCommLayer = new CCommLayerServerDBus(); -// m_pCommLayer = new CCommLayerServerSocket(); - m_pCommLayer->Attach(this); +// m_pCommLayer = new CCommLayerServerDBus(); +// m_pCommLayer = new CCommLayerServerSocket(); + m_pCommLayer->Attach(this); - if((m_nFd = inotify_init()) == -1) - { - throw CABRTException(EXCEP_FATAL, "CCrashWatcher::CCrashWatcher(): Init Failed"); + if((m_nFd = inotify_init()) == -1) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::CCrashWatcher(): Init Failed"); + } + if((watch = inotify_add_watch(m_nFd, pPath.c_str(), IN_CREATE)) == -1) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::CCrashWatcher(): Add watch failed:" + pPath); + } + m_pGio = g_io_channel_unix_new(m_nFd); } - if((watch = inotify_add_watch(m_nFd, pPath.c_str(), IN_CREATE)) == -1){ - - throw CABRTException(EXCEP_FATAL, "CCrashWatcher::CCrashWatcher(): Add watch failed:" + pPath); + catch (...) + { + /* This restores /proc/sys/kernel/core_pattern, among other things */ + delete m_pMW; + //too? delete m_pCommLayer; + throw; } - m_pGio = g_io_channel_unix_new(m_nFd); } CCrashWatcher::~CCrashWatcher() @@ -519,17 +530,17 @@ void CCrashWatcher::CreatePidFile() void CCrashWatcher::Lock() { int lfp = open(VAR_RUN_LOCK_FILE, O_RDWR|O_CREAT,0640); - if (lfp < 0) - { - throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Lock(): can not open lock file"); - } - if (lockf(lfp,F_TLOCK,0) < 0) - { - throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Lock(): cannot create lock on lockfile"); - } - /* only first instance continues */ - //sprintf(str,"%d\n",getpid()); - //write(lfp,str,strlen(str)); /* record pid to lockfile */ + if (lfp < 0) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Lock(): can not open lock file"); + } + if (lockf(lfp,F_TLOCK,0) < 0) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Lock(): cannot create lock on lockfile"); + } + /* only first instance continues */ + //sprintf(str,"%d\n",getpid()); + //write(lfp,str,strlen(str)); /* record pid to lockfile */ } void CCrashWatcher::StartWatch() @@ -573,7 +584,7 @@ void CCrashWatcher::GStartWatch() void CCrashWatcher::Run() { - Debug("Runnig..."); + Debug("Running..."); Lock(); CreatePidFile(); GStartWatch(); @@ -631,7 +642,7 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) //retval = m_pMW->GetCrashInfos(pUID); //Notify("Sent crash info"); - return retval; + return retval; } map_crash_report_t CCrashWatcher::CreateReport(const std::string &pUUID,const std::string &pUID) diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 94f5e66..ea769c5 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -21,6 +21,9 @@ #include "ABRTException.h" #include <iostream> #include <cstdio> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> CCrashWatcher *g_pCrashWatcher = NULL; @@ -54,7 +57,15 @@ int main(int argc, char** argv) } if(daemonize) { - // forking to background + /* Open stdin to /dev/null. We do it before forking + * in order to emit useful exitcode to the parent + * if open fails */ + close(STDIN_FILENO); + if (open("/dev/null", O_RDWR)) + { + throw CABRTException(EXCEP_FATAL, "Can't open /dev/null"); + } + /* forking to background */ pid_t pid = fork(); if (pid < 0) { @@ -68,9 +79,12 @@ int main(int argc, char** argv) { throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Daemonize(): setsid failed"); } - close(STDIN_FILENO); + /* We must not leave fds 0,1,2 closed. + * Otherwise fprintf(stderr) dumps messages into random fds, etc. */ close(STDOUT_FILENO); close(STDERR_FILENO); + dup(0); + dup(0); } g_pCrashWatcher = new CCrashWatcher(DEBUG_DUMPS_DIR); g_pCrashWatcher->Run(); @@ -83,5 +97,7 @@ int main(int argc, char** argv) { std::cerr << "Cannot create daemon: " << e.what() << std::endl; } + //do we need this? delete g_pCrashWatcher; + return 1; /* Any exit is a failure. Normally we don't exit at all */ } |
