diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-01-10 02:01:35 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-01-10 02:01:35 +0000 |
commit | 056eafd420cb0a726953f12da887354c5526ccce (patch) | |
tree | 9be7dfa2d393dce1987f229518375848ff7f0207 /llvm/lib/Support/LockFileManager.cpp | |
parent | 95585ab6a44edc0a56eec3572684d6e72828fc0d (diff) | |
download | bcm5719-llvm-056eafd420cb0a726953f12da887354c5526ccce.tar.gz bcm5719-llvm-056eafd420cb0a726953f12da887354c5526ccce.zip |
Fix a race condition in the lock-file manager: once the lock file is
gone, check for the actual file we care about.
llvm-svn: 172033
Diffstat (limited to 'llvm/lib/Support/LockFileManager.cpp')
-rw-r--r-- | llvm/lib/Support/LockFileManager.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Support/LockFileManager.cpp b/llvm/lib/Support/LockFileManager.cpp index 075d8a5a669..31eec751b7b 100644 --- a/llvm/lib/Support/LockFileManager.cpp +++ b/llvm/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; |