diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 4 | ||||
-rw-r--r-- | lib/Plugins/CCpp.cpp | 7 | ||||
-rw-r--r-- | lib/Utils/DebugDump.cpp | 26 | ||||
-rw-r--r-- | lib/Utils/DebugDump.h | 5 | ||||
-rw-r--r-- | lib/Utils/Packages.cpp | 2 |
5 files changed, 36 insertions, 8 deletions
diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp index 5a5e39d4..91eff06d 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/lib/MiddleWare/MiddleWare.cpp @@ -111,6 +111,7 @@ void CMiddleWare::DebugDump2Report(const std::string& pDebugDumpDir, CReporter:: { pReport.m_bBinaryData2 = pDebugDumpDir + "/" + FILENAME_BINARYDATA2; } + dd.Close(); } void CMiddleWare::RegisterPlugin(const std::string& pName) @@ -174,6 +175,7 @@ void CMiddleWare::CreateReport(const std::string& pDebugDumpDir, CreateReportLanguage(language, pDebugDumpDir); } DebugDump2Report(pDebugDumpDir, pCrashReport.m_Report); + dd.Close(); } void CMiddleWare::CreateReport(const std::string& pUUID, @@ -273,6 +275,7 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& { dd.Delete(pDebugDumpPath); } + dd.Close(); pCrashInfo.m_sUUID = UUID; pCrashInfo.m_sUID = UID; @@ -308,6 +311,7 @@ CMiddleWare::vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& info.m_sExecutable = data; dd.LoadText(FILENAME_PACKAGE, data); info.m_sPackage = data; + dd.Close(); infos.push_back(info); } diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 657f9ac9..59b2f0e3 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -26,7 +26,7 @@ #include <sstream> #define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" -#define CORE_PATTERN CCPP_HOOK_PATH" %p %s" +#define CORE_PATTERN "|"CCPP_HOOK_PATH" %p %s" CLanguageCCpp::CLanguageCCpp() : m_bMemoryMap(false) @@ -40,7 +40,7 @@ std::string CLanguageCCpp::GetLocalUUID(const std::string& pDebugDumpDir) CDebugDump dd; dd.Open(pDebugDumpDir); dd.LoadBinary(FILENAME_BINARYDATA1, &core, &size); - + dd.Close(); // TODO: compute local UUID ss << size; return ss.str(); @@ -52,7 +52,7 @@ std::string CLanguageCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) std::string backtrace; dd.Open(pDebugDumpDir); dd.LoadText(FILENAME_TEXTDATA1, backtrace); - + dd.Close(); // TODO: compute global UUID ss << backtrace.length(); return ss.str(); @@ -69,6 +69,7 @@ void CLanguageCCpp::CreateReport(const std::string& pDebugDumpDir) { dd.SaveText(FILENAME_TEXTDATA2, "memory map of the crashed C/C++ application"); } + dd.Close(); } void CLanguageCCpp::Init() diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 09e65aea..14b77906 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -33,6 +33,8 @@ #include <sys/procfs.h> #include <ctype.h> #include <time.h> +#include <unistd.h> +#include <stdio.h> CDebugDump::CDebugDump() : m_sDebugDumpDir("") @@ -40,11 +42,21 @@ CDebugDump::CDebugDump() : void CDebugDump::Open(const std::string& pDir) { + int fd; m_sDebugDumpDir = pDir; + std::string lockPath = m_sDebugDumpDir + "/.lock"; if (!ExistFileDir(pDir)) { throw "CDebugDump::CDebugDump(): "+pDir+" does not exist."; } + if ((m_nFD = open(lockPath.c_str(), O_RDWR | O_CREAT, 0640)) < 0) + { + throw std::string("CDebugDump::Open(): can not create lock file"); + } + if (lockf(m_nFD,F_LOCK, 0) < 0) + { + throw std::string("CDebugDump::Open(): cannot lock DebugDump"); + } } bool CDebugDump::Exist(const std::string& pPath) @@ -69,12 +81,11 @@ bool CDebugDump::ExistFileDir(const std::string& pPath) void CDebugDump::Create(const std::string& pDir) { - m_sDebugDumpDir = pDir; - Delete(pDir); if (mkdir(pDir.c_str(), 0755) == -1) { throw "CDebugDump::Create(): Cannot create dir: " + pDir; } + Open(pDir); SaveEnvironment(); SaveTime(); } @@ -85,7 +96,7 @@ void CDebugDump::Delete(const std::string& pDir) { return; } - + Open(pDir); DIR *dir = opendir(pDir.c_str()); std::string fullPath; struct dirent *dent = NULL; @@ -112,6 +123,15 @@ void CDebugDump::Delete(const std::string& pDir) throw "CDebugDump::DeleteDir(): Cannot remove dir: " + fullPath; } } + Close(); +} + +void CDebugDump::Close() +{ + std::string lockPath = m_sDebugDumpDir + "/.lock"; + lockf(m_nFD,F_ULOCK, 0); + close(m_nFD); + remove(lockPath.c_str()); } void CDebugDump::SaveEnvironment() diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index f7e740d7..1217136e 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -44,6 +44,7 @@ class CDebugDump private: std::string m_sDebugDumpDir; + int m_nFD; void SaveEnvironment(); void SaveTime(); @@ -59,10 +60,12 @@ class CDebugDump CDebugDump(); void Open(const std::string& pDir); void Create(const std::string& pDir); + void Delete(const std::string& pDir); + void Close(); + void SaveProc(const std::string& pPID); void SavePackage(); - void Delete(const std::string& pDir); bool Exist(const std::string& pFileName); void LoadText(const std::string& pName, std::string& pData); diff --git a/lib/Utils/Packages.cpp b/lib/Utils/Packages.cpp index 654967df..4c94ef6f 100644 --- a/lib/Utils/Packages.cpp +++ b/lib/Utils/Packages.cpp @@ -46,7 +46,7 @@ std::string CPackages::SearchFile(const std::string& pPath) char *argv[] = {(char*)""}; poptContext context = rpmcliInit(0, argv, NULL); rpmts ts = rpmtsCreate(); - rpmdbMatchIterator iter = rpmtsInitIterator(ts, RPMTAG_BASENAMES, "/usr/sbin/acpid", 0); + rpmdbMatchIterator iter = rpmtsInitIterator(ts, RPMTAG_BASENAMES, pPath.c_str(), 0); Header header; char* nerv = NULL; |