summaryrefslogtreecommitdiff
path: root/lib/Support/LockFileManager.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-01-10 02:01:35 +0000
committerDouglas Gregor <dgregor@apple.com>2013-01-10 02:01:35 +0000
commit69a2d6f55afb2bc42bc19e754bcebee39ecdb8bc (patch)
treeace95ba106babbaeab016c25c56d42a5c0292d4d /lib/Support/LockFileManager.cpp
parent06c7008e30d3e278f2d779135ff2ce50bfc643fc (diff)
downloadllvm-69a2d6f55afb2bc42bc19e754bcebee39ecdb8bc.tar.gz
llvm-69a2d6f55afb2bc42bc19e754bcebee39ecdb8bc.tar.bz2
llvm-69a2d6f55afb2bc42bc19e754bcebee39ecdb8bc.tar.xz
Fix a race condition in the lock-file manager: once the lock file is
gone, check for the actual file we care about. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172033 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/LockFileManager.cpp')
-rw-r--r--lib/Support/LockFileManager.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp
index 075d8a5a66..31eec751b7 100644
--- a/lib/Support/LockFileManager.cpp
+++ b/lib/Support/LockFileManager.cpp
@@ -64,6 +64,7 @@ bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) {
LockFileManager::LockFileManager(StringRef FileName)
{
+ this->FileName = FileName;
LockFileName = FileName;
LockFileName += ".lock";
@@ -175,6 +176,7 @@ void LockFileManager::waitForUnlock() {
#endif
// Don't wait more than an hour for the file to appear.
const unsigned MaxSeconds = 3600;
+ bool LockFileGone = false;
do {
// Sleep for the designated interval, to allow the owning process time to
// finish up and remove the lock file.
@@ -185,10 +187,18 @@ void LockFileManager::waitForUnlock() {
#else
nanosleep(&Interval, NULL);
#endif
- // If the file no longer exists, we're done.
+ // If the lock file no longer exists, wait for the actual file.
bool Exists = false;
- if (!sys::fs::exists(LockFileName.str(), Exists) && !Exists)
- return;
+ if (!LockFileGone) {
+ if (!sys::fs::exists(LockFileName.str(), Exists) && !Exists) {
+ LockFileGone = true;
+ Exists = false;
+ }
+ }
+ if (LockFileGone) {
+ if (!sys::fs::exists(FileName.str(), Exists) && Exists)
+ return;
+ }
if (!processStillExecuting((*Owner).first, (*Owner).second))
return;