summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-02-12 16:26:54 +0100
committerZdenek Prikryl <zprikryl@redhat.com>2009-02-12 16:26:54 +0100
commit3541999cd3338818cd86583383dbca87606d49fa (patch)
treecfdacff29ee52da415361c79b74582e51392bf0d
parente608c17a82071fb490df198155a1e022857f9cf0 (diff)
downloadabrt-3541999cd3338818cd86583383dbca87606d49fa.tar.gz
abrt-3541999cd3338818cd86583383dbca87606d49fa.tar.xz
abrt-3541999cd3338818cd86583383dbca87606d49fa.zip
added lock functionality to DebugDump
-rw-r--r--lib/MiddleWare/MiddleWare.cpp4
-rw-r--r--lib/Plugins/CCpp.cpp5
-rw-r--r--lib/Utils/DebugDump.cpp28
-rw-r--r--lib/Utils/DebugDump.h5
-rw-r--r--src/Hooks/CCpp.cpp1
5 files changed, 36 insertions, 7 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 1ac92a0e..59b2f0e3 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -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 6c983e3d..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()
@@ -274,7 +294,7 @@ void CDebugDump::SavePackage()
{
CPackages packages;
LoadText(FILENAME_EXECUTABLE, executable);
- package = packages.SearchFile(executable);
+ package = packages.SearchFile("/usr/sbin/acpid");
}
SaveText(FILENAME_PACKAGE, package);
}
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/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index ba82c286..e3a12971 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -83,6 +83,7 @@ int main(int argc, char** argv)
ii++;
}
dd.SaveBinary(FILENAME_BINARYDATA1, core, ii);
+ dd.Close();
free(core);
}
catch (std::string sError)