summaryrefslogtreecommitdiffstats
path: root/lib/Utils/DebugDump.cpp
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-02-18 11:57:56 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-02-18 11:57:56 +0100
commit0979cbdd39166d6b5a42380e3ff6297e77d1236d (patch)
treeb6de00056eb26b5cd995db09b3dfcbb9ecbd21d6 /lib/Utils/DebugDump.cpp
parent5c22d0c110b8678509817abf9ecf10e3f48525d5 (diff)
parent77ef93c89e3fa75d1a5c0f126bcbb001a152bacf (diff)
downloadabrt-0979cbdd39166d6b5a42380e3ff6297e77d1236d.tar.gz
abrt-0979cbdd39166d6b5a42380e3ff6297e77d1236d.tar.xz
abrt-0979cbdd39166d6b5a42380e3ff6297e77d1236d.zip
Merge branch 'master' of git://git.fedorahosted.org/git/crash-catcher
Diffstat (limited to 'lib/Utils/DebugDump.cpp')
-rw-r--r--lib/Utils/DebugDump.cpp45
1 files changed, 29 insertions, 16 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index 19d3a2be..f09de9ea 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -38,7 +38,7 @@
CDebugDump::CDebugDump() :
m_sDebugDumpDir(""),
m_nFD(0),
- m_bLockCreated(false)
+ m_bUnlock(true)
{}
void CDebugDump::Open(const std::string& pDir)
@@ -77,35 +77,48 @@ void CDebugDump::Lock()
std::string lockPath = m_sDebugDumpDir + ".lock";
if (ExistFileDir(lockPath))
{
- if ((m_nFD = open(lockPath.c_str(), O_RDWR | O_CREAT, 0640)) < 0)
+ int res;
+ if ((m_nFD = open(lockPath.c_str(), O_RDWR)) < 0)
{
- throw std::string("CDebugDump::Create(): can not create lock file");
+ throw std::string("CDebugDump::Lock(): can not create lock file");
}
- m_bLockCreated = false;
- }
- else
- {
- if ((m_nFD = open(lockPath.c_str(), O_RDWR | O_CREAT, 0640)) < 0)
+ res = lockf(m_nFD, F_TEST, 0);
+ if (res < 0)
+ {
+ throw std::string("CDebugDump::Lock(): cannot lock DebugDump");
+ }
+ else if (res == 0)
{
- throw std::string("CDebugDump::Create(): can not create lock file");
+ close(m_nFD);
+ m_bUnlock = false;
+ return;
}
- m_bLockCreated = true;
+ while (ExistFileDir(lockPath))
+ {
+ std::cerr << "CDebugDump::Lock(): waiting..." << std::endl;
+ usleep(10);
+ }
+ }
+
+ if ((m_nFD = open(lockPath.c_str(), O_RDWR | O_CREAT, 0640)) < 0)
+ {
+ throw std::string("CDebugDump::Lock(): can not create lock file");
}
if (lockf(m_nFD,F_LOCK, 0) < 0)
{
- throw std::string("CDebugDump::Create(): cannot lock DebugDump");
+ throw std::string("CDebugDump::Lock(): cannot lock DebugDump");
}
}
void CDebugDump::UnLock()
{
std::string lockPath = m_sDebugDumpDir + ".lock";
- lockf(m_nFD,F_ULOCK, 0);
- close(m_nFD);
- if (m_bLockCreated)
+ if (m_bUnlock)
{
+ lockf(m_nFD,F_ULOCK, 0);
+ close(m_nFD);
remove(lockPath.c_str());
- m_bLockCreated = false;
+ m_bUnlock = true;
}
}
@@ -330,7 +343,7 @@ void CDebugDump::SavePackage()
{
CPackages packages;
LoadText(FILENAME_EXECUTABLE, executable);
- package = packages.SearchFile("/usr/sbin/acpid");
+ package = packages.SearchFile(executable);
}
SaveText(FILENAME_PACKAGE, package);
}