std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" "));
int PID;
- if (!PIDStr.getAsInteger(10, PID))
- return std::make_pair(std::string(Hostname), PID);
+ if (!PIDStr.getAsInteger(10, PID)) {
+ auto Owner = std::make_pair(std::string(Hostname), PID);
+ if (processStillExecuting(Owner.first, Owner.second))
+ return Owner;
+ }
// Delete the lock file. It's invalid anyway.
sys::fs::remove(LockFileName);
LockFileManager::LockFileManager(StringRef FileName)
{
this->FileName = FileName;
- LockFileName = FileName;
+ if (error_code EC = sys::fs::make_absolute(this->FileName)) {
+ Error = EC;
+ return;
+ }
+ LockFileName = this->FileName;
LockFileName += ".lock";
// If the lock file already exists, don't bother to try to create our own
if (Out.has_error()) {
// We failed to write out PID, so make up an excuse, remove the
// unique lock file, and fail.
- Error = make_error_code(errc::no_space_on_device);
+ Error = make_error_code(std::errc::no_space_on_device);
sys::fs::remove(UniqueLockFileName.c_str());
return;
}
while (1) {
// Create a link from the lock file name. If this succeeds, we're done.
error_code EC =
- sys::fs::create_link(sys::path::filename(UniqueLockFileName.str()),
- LockFileName.str());
- if (EC == errc::success)
+ sys::fs::create_link(UniqueLockFileName.str(), LockFileName.str());
+ if (!EC)
return;
- if (EC != errc::file_exists) {
+ if (EC != std::errc::file_exists) {
Error = EC;
return;
}
sys::fs::remove(UniqueLockFileName.str());
}
-void LockFileManager::waitForUnlock() {
+LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
if (getState() != LFS_Shared)
- return;
+ return Res_Success;
#if LLVM_ON_WIN32
unsigned long Interval = 1;
#if LLVM_ON_WIN32
Sleep(Interval);
#else
- nanosleep(&Interval, NULL);
+ nanosleep(&Interval, nullptr);
#endif
bool LockFileJustDisappeared = false;
// available now.
if (LockFileGone) {
if (sys::fs::exists(FileName.str())) {
- return;
+ return Res_Success;
}
// The lock file is gone, so now we're waiting for the original file to
// owning the lock died without cleaning up, just bail out.
if (!LockFileGone &&
!processStillExecuting((*Owner).first, (*Owner).second)) {
- return;
+ return Res_OwnerDied;
}
// Exponentially increase the time we wait for the lock to be removed.
);
// Give up.
+ return Res_Timeout;
}