<div dir="ltr">Uh...<div><br></div><div>Why not just check for the header and use that? Or check for the functions you need etc at configure/cmake time?</div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 29, 2015 at 3:19 PM Ben Langmuir <<a href="mailto:blangmuir@apple.com">blangmuir@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: benlangmuir<br>
Date: Mon Jun 29 17:16:39 2015<br>
New Revision: 241012<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D241012-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=D9hskwjV2rG_KYEXMHZ7-w2AIW7-22YNbpTmC3lVCn8&s=Byp3n-p6YnJOxBXwBbPJQICAyL0_iKyx2CXdhNQURok&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=241012&view=rev</a><br>
Log:<br>
Reapply "Use gethostuuid() on Mac to identify hosts for LockFileManager"<br>
<br>
Reapplies r241005 after fixing the build on non-Mac platforms. Original<br>
commit message below.<br>
<br>
The hostname can be very unstable when there are many machines on the<br>
network competing for the same name. Using the hardware UUID makes it<br>
less likely to have collisions or to consider files written by the<br>
current host to be owned by a different one at a later time.<br>
<br>
rdar://problem/21512307<br>
<br>
Modified:<br>
    llvm/trunk/lib/Support/LockFileManager.cpp<br>
<br>
Modified: llvm/trunk/lib/Support/LockFileManager.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Support_LockFileManager.cpp-3Frev-3D241012-26r1-3D241011-26r2-3D241012-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=D9hskwjV2rG_KYEXMHZ7-w2AIW7-22YNbpTmC3lVCn8&s=vjjh6E2cOnvrQ81L0QcbXF3yJUfsKKL6SaFSUNEtR4I&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=241012&r1=241011&r2=241012&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/LockFileManager.cpp (original)<br>
+++ llvm/trunk/lib/Support/LockFileManager.cpp Mon Jun 29 17:16:39 2015<br>
@@ -21,6 +21,16 @@<br>
 #if LLVM_ON_UNIX<br>
 #include <unistd.h><br>
 #endif<br>
+<br>
+#if defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (__MAC_OS_X_VERSION_MIN_REQUIRED > 1050)<br>
+#define USE_OSX_GETHOSTUUID 1<br>
+#else<br>
+#define USE_OSX_GETHOSTUUID 0<br>
+#endif<br>
+<br>
+#if USE_OSX_GETHOSTUUID<br>
+#include <uuid/uuid.h><br>
+#endif<br>
 using namespace llvm;<br>
<br>
 /// \brief Attempt to read the lock file with the given name, if it exists.<br>
@@ -56,14 +66,45 @@ LockFileManager::readLockFile(StringRef<br>
   return None;<br>
 }<br>
<br>
-bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) {<br>
+static std::error_code getHostID(SmallVectorImpl<char> &HostID) {<br>
+  HostID.clear();<br>
+<br>
+#if USE_OSX_GETHOSTUUID<br>
+  // On OS X, use the more stable hardware UUID instead of hostname.<br>
+  struct timespec wait = {1, 0}; // 1 second.<br>
+  uuid_t uuid;<br>
+  if (gethostuuid(uuid, &wait) != 0)<br>
+    return std::error_code(errno, std::system_category());<br>
+<br>
+  uuid_string_t UUIDStr;<br>
+  uuid_unparse(uuid, UUIDStr);<br>
+  StringRef UUIDRef(UUIDStr);<br>
+  HostID.append(UUIDRef.begin(), UUIDRef.end());<br>
+<br>
+#elif LLVM_ON_UNIX<br>
+  char HostName[256];<br>
+  HostName[255] = 0;<br>
+  HostName[0] = 0;<br>
+  gethostname(HostName, 255);<br>
+  StringRef HostNameRef(HostName);<br>
+  HostID.append(HostNameRef.begin(), HostNameRef.end());<br>
+<br>
+#else<br>
+  StringRef Dummy("localhost");<br>
+  HostID.append(Dummy.begin(), Dummy.end());<br>
+#endif<br>
+<br>
+  return std::error_code();<br>
+}<br>
+<br>
+bool LockFileManager::processStillExecuting(StringRef HostID, int PID) {<br>
 #if LLVM_ON_UNIX && !defined(__ANDROID__)<br>
-  char MyHostname[256];<br>
-  MyHostname[255] = 0;<br>
-  MyHostname[0] = 0;<br>
-  gethostname(MyHostname, 255);<br>
+  SmallString<256> StoredHostID;<br>
+  if (getHostID(StoredHostID))<br>
+    return true; // Conservatively assume it's executing on error.<br>
+<br>
   // Check whether the process is dead. If so, we're done.<br>
-  if (MyHostname == Hostname && getsid(PID) == -1 && errno == ESRCH)<br>
+  if (StoredHostID == HostID && getsid(PID) == -1 && errno == ESRCH)<br>
     return false;<br>
 #endif<br>
<br>
@@ -126,17 +167,18 @@ LockFileManager::LockFileManager(StringR<br>
<br>
   // Write our process ID to our unique lock file.<br>
   {<br>
-    raw_fd_ostream Out(UniqueLockFileID, /*shouldClose=*/true);<br>
+    SmallString<256> HostID;<br>
+    if (auto EC = getHostID(HostID)) {<br>
+      Error = EC;<br>
+      return;<br>
+    }<br>
<br>
+    raw_fd_ostream Out(UniqueLockFileID, /*shouldClose=*/true);<br>
+    Out << HostID << ' ';<br>
 #if LLVM_ON_UNIX<br>
-    // FIXME: move getpid() call into LLVM<br>
-    char hostname[256];<br>
-    hostname[255] = 0;<br>
-    hostname[0] = 0;<br>
-    gethostname(hostname, 255);<br>
-    Out << hostname << ' ' << getpid();<br>
+    Out << getpid();<br>
 #else<br>
-    Out << "localhost 1";<br>
+    Out << "1";<br>
 #endif<br>
     Out.close();<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>