From 39d77b6cfa633b94a31de5ec387949a7c7b85623 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 9 Sep 2009 19:04:42 +0200 Subject: fix the bug where lock file was not removed Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 3 --- lib/Plugins/KerneloopsScanner.cpp | 3 +-- lib/Plugins/Python.cpp | 19 +++++++++---------- lib/Plugins/RunApp.cpp | 1 - lib/Plugins/SOSreport.cpp | 3 +-- lib/Utils/DebugDump.cpp | 9 +++++++++ lib/Utils/DebugDump.h | 2 ++ 7 files changed, 22 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 995ddbeb..2f8d3559 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -190,7 +190,6 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra dd.Open(pDebugDumpDir); dd.LoadText(FILENAME_EXECUTABLE, executable); dd.LoadText(FILENAME_UID, UID); - dd.Close(); fTmp << "file " << executable << std::endl; fTmp << "core " << pDebugDumpDir << "/" << FILENAME_COREDUMP << std::endl; fTmp << "thread apply all backtrace full" << std::endl; @@ -479,7 +478,6 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir) dd.Open(pDebugDumpDir); if (dd.Exist(FILENAME_BACKTRACE)) { - dd.Close(); return; } dd.LoadText(FILENAME_PACKAGE, package); @@ -503,7 +501,6 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir) { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); } - dd.Close(); } void CAnalyzerCCpp::Init() diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index 63460ba0..e1e32284 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -79,7 +79,6 @@ void CKerneloopsScanner::SaveOopsToDebugDump() update_client(_("Creating kernel oops crash reports...")); time_t t = time(NULL); - CDebugDump debugDump; std::list oopsList = m_pSysLog.GetOopsList(); m_pSysLog.ClearOopsList(); @@ -92,13 +91,13 @@ void CKerneloopsScanner::SaveOopsToDebugDump() try { + CDebugDump debugDump; debugDump.Create(path, 0); debugDump.SaveText(FILENAME_ANALYZER, "Kerneloops"); debugDump.SaveText(FILENAME_EXECUTABLE, "kernel"); debugDump.SaveText(FILENAME_KERNEL, oops.m_sVersion); debugDump.SaveText(FILENAME_PACKAGE, "not_applicable"); debugDump.SaveText(FILENAME_KERNELOOPS, oops.m_sData); - debugDump.Close(); } catch (CABRTException& e) { diff --git a/lib/Plugins/Python.cpp b/lib/Plugins/Python.cpp index c3677e7b..3e6926cd 100644 --- a/lib/Plugins/Python.cpp +++ b/lib/Plugins/Python.cpp @@ -9,21 +9,20 @@ std::string CAnalyzerPython::CreateHash(const std::string& pDebugDumpDir) { - std::string uuid; - CDebugDump dd; - dd.Open(pDebugDumpDir); - dd.LoadText("uuid", uuid); - dd.Close(); - return uuid; + std::string uuid; + CDebugDump dd; + dd.Open(pDebugDumpDir); + dd.LoadText("uuid", uuid); + return uuid; } std::string CAnalyzerPython::GetLocalUUID(const std::string& pDebugDumpDir) { - return CreateHash(pDebugDumpDir); + return CreateHash(pDebugDumpDir); } std::string CAnalyzerPython::GetGlobalUUID(const std::string& pDebugDumpDir) { - return GetLocalUUID(pDebugDumpDir); + return GetLocalUUID(pDebugDumpDir); } void CAnalyzerPython::Init() @@ -39,8 +38,8 @@ void CAnalyzerPython::Init() void CAnalyzerPython::DeInit() { - // TODO: remove copied abrt exception handler - std::ofstream fOutPySiteCustomize; + // TODO: remove copied abrt exception handler + std::ofstream fOutPySiteCustomize; fOutPySiteCustomize.open(PYHOOK_CONFIG); if (fOutPySiteCustomize.is_open()) { diff --git a/lib/Plugins/RunApp.cpp b/lib/Plugins/RunApp.cpp index fdbc3a75..5a5c1d44 100644 --- a/lib/Plugins/RunApp.cpp +++ b/lib/Plugins/RunApp.cpp @@ -84,7 +84,6 @@ void CActionRunApp::Run(const std::string& pActionDir, CDebugDump dd; dd.Open(pActionDir); dd.SaveText(args[FILENAME].c_str(), output); - dd.Close(); } } diff --git a/lib/Plugins/SOSreport.cpp b/lib/Plugins/SOSreport.cpp index c92b4fee..0e47ff84 100644 --- a/lib/Plugins/SOSreport.cpp +++ b/lib/Plugins/SOSreport.cpp @@ -159,10 +159,9 @@ void CActionSOSreport::Run(const std::string& pActionDir, CDebugDump dd; dd.Open(pActionDir); - //Not usefull + //Not useful //dd.SaveText("sosreportoutput", output); CopyFile(sosreport_filename,sosreport_dd_filename); - dd.Close(); } PLUGIN_INFO(ACTION, diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 6eb58369..03fb7c64 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -48,6 +48,7 @@ static bool isdigit_str(const char *str) if (*str < '0' || *str > '9') return false; str++; } + return true; } static std::string RemoveBackSlashes(const std::string& pDir); @@ -105,6 +106,7 @@ static int GetAndSetLock(const char* pLockFile, const char* pPID) if (errno != EEXIST) perror_msg_and_die("Can't create lock file '%s'", pLockFile); fd = open(pLockFile, O_RDONLY); +log("opened O_RDONLY: '%s'", pLockFile); if (fd < 0) { if (errno == ENOENT) @@ -123,6 +125,7 @@ static int GetAndSetLock(const char* pLockFile, const char* pPID) continue; } pid_buf[r] = '\0'; +log("read: '%s'", pid_buf); if (strcmp(pid_buf, pPID) == 0) { log("Lock file '%s' is already locked by us", pLockFile); @@ -140,6 +143,7 @@ static int GetAndSetLock(const char* pLockFile, const char* pPID) /* The file may be deleted by now by other process. Ignore errors */ unlink(pLockFile); } +log("created O_EXCL: '%s'", pLockFile); int len = strlen(pPID); if (write(fd, pPID, len) != len) @@ -304,6 +308,11 @@ void CDebugDump::Delete() void CDebugDump::Close() { UnLock(); + if (m_pGetNextFileDir != NULL) + { + closedir(m_pGetNextFileDir); + m_pGetNextFileDir = NULL; + } m_bOpened = false; } diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index 473f8d45..4b1ec8ed 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -55,6 +55,8 @@ class CDebugDump public: CDebugDump(); + ~CDebugDump() { Close(); } + void Open(const std::string& pDir); void Create(const std::string& pDir, uid_t nUID); void Delete(); -- cgit