diff options
| author | Zdenek Prikryl <zprikryl@redhat.com> | 2009-02-12 16:26:54 +0100 |
|---|---|---|
| committer | Zdenek Prikryl <zprikryl@redhat.com> | 2009-02-12 16:26:54 +0100 |
| commit | 3541999cd3338818cd86583383dbca87606d49fa (patch) | |
| tree | cfdacff29ee52da415361c79b74582e51392bf0d /lib/Utils | |
| parent | e608c17a82071fb490df198155a1e022857f9cf0 (diff) | |
| download | abrt-3541999cd3338818cd86583383dbca87606d49fa.tar.gz abrt-3541999cd3338818cd86583383dbca87606d49fa.tar.xz abrt-3541999cd3338818cd86583383dbca87606d49fa.zip | |
added lock functionality to DebugDump
Diffstat (limited to 'lib/Utils')
| -rw-r--r-- | lib/Utils/DebugDump.cpp | 28 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.h | 5 |
2 files changed, 28 insertions, 5 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); } diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index f7e740d..1217136 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); |
