- int PID = 0;
- std::string Hostname;
- std::ifstream Input(LockFileName.str().c_str());
- if (Input >> Hostname >> PID && PID > 0 &&
- processStillExecuting(Hostname, PID))
- return std::make_pair(Hostname, PID);
+ std::unique_ptr<MemoryBuffer> MB;
+ if (MemoryBuffer::getFile(LockFileName, MB)) {
+ sys::fs::remove(LockFileName);
+ return None;
+ }
+
+ StringRef Hostname;
+ StringRef PIDStr;
+ std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
+ PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" "));
+ int PID;
+ if (!PIDStr.getAsInteger(10, PID)) {
+ auto Owner = std::make_pair(std::string(Hostname), PID);
+ if (processStillExecuting(Owner.first, Owner.second))
+ return Owner;
+ }