<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 29, 2015, at 3:28 PM, Eric Christopher <<a href="mailto:echristo@gmail.com" class="">echristo@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, Jun 29, 2015 at 3:26 PM Ben Langmuir <<a href="mailto:blangmuir@apple.com" class="">blangmuir@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 29, 2015, at 3:20 PM, Eric Christopher <<a href="mailto:echristo@gmail.com" target="_blank" class="">echristo@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Uh...<div class=""><br class=""></div><div class="">Why not just check for the header and use that?</div></div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class="">gethostuuid() is defined in unistd.h on recent versions of Mac.  The presence of uuid.h is necessary but not sufficient.</div></div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">IIRC I put in some other checks for uuid.h at one point, you might want to audit it.</div></div></div></div></blockquote><div><br class=""></div><div>I can’t find any other use of uuid.h in llvm or clang.  Do you recall where this was?</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class=""><br class=""></div><div class="">That said, you can still check for the function in the available headers...</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""> Or check for the functions you need etc at configure/cmake time?</div></div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class="">Sadly, on some platforms and/or versions where this function exists, it returns a bogus value.</div></div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Released versions?</div></div></div></div></blockquote><div><br class=""></div>Yes.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class=""><br class=""></div><div class="">If so, this is just bogus all over the place. :\ That said you could restrict the use by known good versions or write checks to make sure that it's valid to use rather than #ifdef'ing them.</div></div></div></div></blockquote><div><br class=""></div><div>I’m not sure I understand - are you suggesting moving the platform-specific #ifdef I’m using into the configuration stage, or are you suggesting checking the validity of the return values directly?  If the latter, then unfortunately the “bad” values aren’t readily distinguishable, they’re just not “unique” enough.</div><div><br class=""></div><div>Ben</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class=""><br class=""></div><div class="">-eric</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">-eric</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, Jun 29, 2015 at 3:19 PM Ben Langmuir <<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: benlangmuir<br class="">
Date: Mon Jun 29 17:16:39 2015<br class="">
New Revision: 241012<br class="">
<br class="">
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=Q5gk-RCkK86MlqMWQkYSTlNIfQ0yjGVGox6n5D0HYfM&s=vIIvPUuitbqkzHi3pvUZtEQ7mpIy8UzZh9htblG18_4&e=" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=241012&view=rev</a><br class="">
Log:<br class="">
Reapply "Use gethostuuid() on Mac to identify hosts for LockFileManager"<br class="">
<br class="">
Reapplies r241005 after fixing the build on non-Mac platforms. Original<br class="">
commit message below.<br class="">
<br class="">
The hostname can be very unstable when there are many machines on the<br class="">
network competing for the same name. Using the hardware UUID makes it<br class="">
less likely to have collisions or to consider files written by the<br class="">
current host to be owned by a different one at a later time.<br class="">
<br class="">
<a class="">rdar://problem/21512307</a><br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/lib/Support/LockFileManager.cpp<br class="">
<br class="">
Modified: llvm/trunk/lib/Support/LockFileManager.cpp<br class="">
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=Q5gk-RCkK86MlqMWQkYSTlNIfQ0yjGVGox6n5D0HYfM&s=h-nUb4WGdFOhNUfXRjFpmaNAKXb7vg7lru5nvdatxng&e=" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=241012&r1=241011&r2=241012&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/Support/LockFileManager.cpp (original)<br class="">
+++ llvm/trunk/lib/Support/LockFileManager.cpp Mon Jun 29 17:16:39 2015<br class="">
@@ -21,6 +21,16 @@<br class="">
 #if LLVM_ON_UNIX<br class="">
 #include <unistd.h><br class="">
 #endif<br class="">
+<br class="">
+#if defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (__MAC_OS_X_VERSION_MIN_REQUIRED > 1050)<br class="">
+#define USE_OSX_GETHOSTUUID 1<br class="">
+#else<br class="">
+#define USE_OSX_GETHOSTUUID 0<br class="">
+#endif<br class="">
+<br class="">
+#if USE_OSX_GETHOSTUUID<br class="">
+#include <uuid/uuid.h><br class="">
+#endif<br class="">
 using namespace llvm;<br class="">
<br class="">
 /// \brief Attempt to read the lock file with the given name, if it exists.<br class="">
@@ -56,14 +66,45 @@ LockFileManager::readLockFile(StringRef<br class="">
   return None;<br class="">
 }<br class="">
<br class="">
-bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) {<br class="">
+static std::error_code getHostID(SmallVectorImpl<char> &HostID) {<br class="">
+  HostID.clear();<br class="">
+<br class="">
+#if USE_OSX_GETHOSTUUID<br class="">
+  // On OS X, use the more stable hardware UUID instead of hostname.<br class="">
+  struct timespec wait = {1, 0}; // 1 second.<br class="">
+  uuid_t uuid;<br class="">
+  if (gethostuuid(uuid, &wait) != 0)<br class="">
+    return std::error_code(errno, std::system_category());<br class="">
+<br class="">
+  uuid_string_t UUIDStr;<br class="">
+  uuid_unparse(uuid, UUIDStr);<br class="">
+  StringRef UUIDRef(UUIDStr);<br class="">
+  HostID.append(UUIDRef.begin(), UUIDRef.end());<br class="">
+<br class="">
+#elif LLVM_ON_UNIX<br class="">
+  char HostName[256];<br class="">
+  HostName[255] = 0;<br class="">
+  HostName[0] = 0;<br class="">
+  gethostname(HostName, 255);<br class="">
+  StringRef HostNameRef(HostName);<br class="">
+  HostID.append(HostNameRef.begin(), HostNameRef.end());<br class="">
+<br class="">
+#else<br class="">
+  StringRef Dummy("localhost");<br class="">
+  HostID.append(Dummy.begin(), Dummy.end());<br class="">
+#endif<br class="">
+<br class="">
+  return std::error_code();<br class="">
+}<br class="">
+<br class="">
+bool LockFileManager::processStillExecuting(StringRef HostID, int PID) {<br class="">
 #if LLVM_ON_UNIX && !defined(__ANDROID__)<br class="">
-  char MyHostname[256];<br class="">
-  MyHostname[255] = 0;<br class="">
-  MyHostname[0] = 0;<br class="">
-  gethostname(MyHostname, 255);<br class="">
+  SmallString<256> StoredHostID;<br class="">
+  if (getHostID(StoredHostID))<br class="">
+    return true; // Conservatively assume it's executing on error.<br class="">
+<br class="">
   // Check whether the process is dead. If so, we're done.<br class="">
-  if (MyHostname == Hostname && getsid(PID) == -1 && errno == ESRCH)<br class="">
+  if (StoredHostID == HostID && getsid(PID) == -1 && errno == ESRCH)<br class="">
     return false;<br class="">
 #endif<br class="">
<br class="">
@@ -126,17 +167,18 @@ LockFileManager::LockFileManager(StringR<br class="">
<br class="">
   // Write our process ID to our unique lock file.<br class="">
   {<br class="">
-    raw_fd_ostream Out(UniqueLockFileID, /*shouldClose=*/true);<br class="">
+    SmallString<256> HostID;<br class="">
+    if (auto EC = getHostID(HostID)) {<br class="">
+      Error = EC;<br class="">
+      return;<br class="">
+    }<br class="">
<br class="">
+    raw_fd_ostream Out(UniqueLockFileID, /*shouldClose=*/true);<br class="">
+    Out << HostID << ' ';<br class="">
 #if LLVM_ON_UNIX<br class="">
-    // FIXME: move getpid() call into LLVM<br class="">
-    char hostname[256];<br class="">
-    hostname[255] = 0;<br class="">
-    hostname[0] = 0;<br class="">
-    gethostname(hostname, 255);<br class="">
-    Out << hostname << ' ' << getpid();<br class="">
+    Out << getpid();<br class="">
 #else<br class="">
-    Out << "localhost 1";<br class="">
+    Out << "1";<br class="">
 #endif<br class="">
     Out.close();<br class="">
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div>
</div></blockquote></div></div></blockquote></div></div>
</div></blockquote></div><br class=""></body></html>