]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Hack to get the TSAN case working (it just calls _exit())
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 17 Dec 2024 16:07:10 +0000 (17:07 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 10 Feb 2025 13:01:07 +0000 (14:01 +0100)
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-main.hh
pdns/recursordist/rec_channel.cc
pdns/recursordist/rec_channel_rec.cc

index 7d60e5dc51a0f47a2d26f8596ee51e4596cd763c..00b1b8f67bb463707c0fcbaadfa0aaed4044301e 100644 (file)
@@ -3156,7 +3156,7 @@ static void setupLogging(const string& logname)
   }
 }
 
-DoneRunning doneRunning;
+DoneRunning g_doneRunning;
 
 int main(int argc, char** argv)
 {
@@ -3330,9 +3330,9 @@ int main(int argc, char** argv)
 
     ret = serviceMain(startupLog);
     {
-      std::lock_guard lock(doneRunning.mutex);
-      doneRunning.done = true;
-      doneRunning.condVar.notify_one();
+      std::lock_guard lock(g_doneRunning.mutex);
+      g_doneRunning.done = true;
+      g_doneRunning.condVar.notify_one();
     }
     RecThreadInfo::joinThread0();
   }
index 3709e1c721dd84745d682eb9ae581dfe00cbd91e..5ec3018f30232feb94c8b0b8b3fe7e836d3d5b4f 100644 (file)
@@ -161,7 +161,7 @@ struct DoneRunning
   std::condition_variable condVar;
   std::atomic<bool> done{false};
 };
-extern DoneRunning doneRunning;
+extern DoneRunning g_doneRunning;
 
 // you can ask this class for a UDP socket to send a query from
 // this socket is not yours, don't even think about deleting it
index 6abab97a35fceb94b636ad5256d7b28af751bd16..47a1832d0c4858101292b1aca5029cffe6834249 100644 (file)
 
 #include "namespaces.hh"
 
+/* g++ defines __SANITIZE_THREAD__
+   clang++ supports the nice __has_feature(thread_sanitizer),
+   let's merge them */
+#if defined(__has_feature)
+#if __has_feature(thread_sanitizer)
+#define __SANITIZE_THREAD__ 1
+#endif
+#if __has_feature(address_sanitizer)
+#define __SANITIZE_ADDRESS__ 1
+#endif
+#endif
+
 std::atomic<bool> RecursorControlChannel::stop = false;
 
 RecursorControlChannel::RecursorControlChannel()
@@ -188,8 +200,15 @@ RecursorControlChannel::Answer RecursorControlChannel::recv(int fd, unsigned int
   const time_t start = time(nullptr);
 
   waitForRead(fd, timeout, start);
-  int err;
-  if (::recv(fd, &err, sizeof(err), 0) != sizeof(err)) {
+  int err{};
+  auto ret = ::recv(fd, &err, sizeof(err), 0);
+  if (ret == 0) {
+#if defined(__SANITIZE_THREAD__)
+    return {0, "bye nicely\n"}; // Hack because TSAN enabled build justs _exits on quit-nicely
+#endif
+    throw PDNSException("Unable to receive status over control connection: EOF");
+  }
+  if (ret != sizeof(err)) {
     throw PDNSException("Unable to receive return status over control channel: " + stringerror());
   }
 
index 8d398e9fb4129bb726cbbb8fefaec2a68815d34c..688b88f50ec8ace7371b332ab638a6e4cd031b9a 100644 (file)
@@ -1387,8 +1387,8 @@ void doExitGeneric(bool nicely)
   if (nicely) {
     RecursorControlChannel::stop = true;
     {
-      std::unique_lock lock(doneRunning.mutex);
-      doneRunning.condVar.wait(lock, [] { return doneRunning.done.load(); });
+      std::unique_lock lock(g_doneRunning.mutex);
+      g_doneRunning.condVar.wait(lock, [] { return g_doneRunning.done.load(); });
     }
     // g_rcc.~RecursorControlChannel() do not call, caller still needs it!
   }