<div dir="ltr">On Tue, Aug 6, 2013 at 3:51 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:reid@kleckner.net" target="_blank">reid@kleckner.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Modified: llvm/trunk/lib/Support/LockFileManager.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=187826&r1=187825&r2=187826&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=187826&r1=187825&r2=187826&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Support/LockFileManager.cpp (original)<br>
+++ llvm/trunk/lib/Support/LockFileManager.cpp Tue Aug  6 17:51:21 2013<br>
@@ -7,9 +7,11 @@<br>
 //<br>
 //===----------------------------------------------------------------------===//<br>
 #include "llvm/Support/LockFileManager.h"<br>
+#include "llvm/ADT/STLExtras.h"<br>
+#include "llvm/ADT/StringExtras.h"<br>
 #include "llvm/Support/FileSystem.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
-#include <fstream><br>
 #include <sys/stat.h><br>
 #include <sys/types.h><br>
 #if LLVM_ON_WIN32<br>
@@ -35,16 +37,18 @@ LockFileManager::readLockFile(StringRef<br>
<br>
   // Read the owning host and PID out of the lock file. If it appears that the<br>
   // owning process is dead, the lock file is invalid.<br>
-  int PID = 0;<br>
-  std::string Hostname;<br>
-  std::ifstream Input(LockFileName.str().c_str());<br>
-  if (Input >> Hostname >> PID && PID > 0 &&<br>
-      processStillExecuting(Hostname, PID))<br>
-    return std::make_pair(Hostname, PID);<br>
+  OwningPtr<MemoryBuffer> MB;<br>
+  if (MemoryBuffer::getFile(LockFileName, MB)) {<br></blockquote><div><br></div><div>Speaking of error handling and booleans, it looks like this if condition is wrong, but we don't have any test coverage for it.  D=</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    StringRef Hostname;<br>
+    StringRef PIDStr;<br>
+    tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");<br>
+    int PID;<br>
+    if (PIDStr.getAsInteger(10, PID))<br>
+      return std::make_pair(std::string(Hostname), PID);<br>
+  }<br>
<br>
   // Delete the lock file. It's invalid anyway.<br>
-  bool Existed;<br>
-  sys::fs::remove(LockFileName, Existed);<br>
+  sys::fs::remove(LockFileName);<br>
   return None;<br>
 }<br></blockquote></div></div></div>