summaryrefslogtreecommitdiffstats
path: root/lib/Utils/DebugDump.cpp
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 /lib/Utils/DebugDump.cpp
parente608c17a82071fb490df198155a1e022857f9cf0 (diff)
downloadabrt-3541999cd3338818cd86583383dbca87606d49fa.tar.gz
abrt-3541999cd3338818cd86583383dbca87606d49fa.tar.xz
abrt-3541999cd3338818cd86583383dbca87606d49fa.zip
added lock functionality to DebugDump
Diffstat (limited to 'lib/Utils/DebugDump.cpp')
-rw-r--r--lib/Utils/DebugDump.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index 6c983e3..14b7790 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);
}