<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 29, 2015 at 3:50 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"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Jun 29, 2015, at 3:28 PM, Eric Christopher <<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 29, 2015 at 3:26 PM Ben Langmuir <<a href="mailto:blangmuir@apple.com" target="_blank">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"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Jun 29, 2015, at 3:20 PM, Eric Christopher <<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Uh...<div><br></div><div>Why not just check for the header and use that?</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>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"><div><br></div></div></blockquote><div><br></div><div>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></div></div></div><div style="word-wrap:break-word"><div><div>I can’t find any other use of uuid.h in llvm or clang.  Do you recall where this was?</div></div></div><div style="word-wrap:break-word"><div><br></div></div></blockquote><div><br></div><div>IIRC it was support, but it's been a few years.</div><div> </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"><div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div><br></div><div>That said, you can still check for the function in the available headers...</div><div> </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"><div><blockquote type="cite"><div><div dir="ltr"><div> Or check for the functions you need etc at configure/cmake time?</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>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"><div><br></div></div></blockquote><div><br></div><div>Released versions?</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div>Yes.</div><div></div></div><div style="word-wrap:break-word"><div><br></div></div></blockquote><div><br></div><div>Whee. That said...</div><div> </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"><div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div><br></div><div>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></div></div></div><div style="word-wrap:break-word"><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></div><div style="word-wrap:break-word"><div><div><br></div></div></div></blockquote><div><br></div><div>Since you've got a version of it you can still make it a configure time check rather than a compile one to keep the amount of version specific ifdefs out of the file. If you need help with the autoconf side I can help, the cmake side... I'll punt to Chris B or someone. :)</div><div><br></div><div>-eric</div><div> </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"><div><div></div><div>Ben</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div><br></div><div>-eric</div><div> </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"><div><blockquote type="cite"><div><div dir="ltr"><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" target="_blank">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=4G-5IWoMCJrRH6KzDiiw8uNt0Wag3HkDas2tz92oTSw&s=rmUPB5ermwi4rkYPSp2fgssijqtK9a61U64pQPCCfX0&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>
<a>rdar://problem/21512307</a><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=4G-5IWoMCJrRH6KzDiiw8uNt0Wag3HkDas2tz92oTSw&s=xxp8wkCgukBpDjH-dAaAp27i91vam1o3rdFm6E85PMc&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>
</div></blockquote></div></div></blockquote></div></div>
</div></blockquote></div></div></blockquote></div></div>