From: Otto Moerbeek Date: Tue, 17 Dec 2024 16:07:10 +0000 (+0100) Subject: Hack to get the TSAN case working (it just calls _exit()) X-Git-Tag: dnsdist-2.0.0-alpha1~96^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9646870d4a67ebe279da7f498478270979517d8;p=thirdparty%2Fpdns.git Hack to get the TSAN case working (it just calls _exit()) --- diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 7d60e5dc51..00b1b8f67b 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -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(); } diff --git a/pdns/recursordist/rec-main.hh b/pdns/recursordist/rec-main.hh index 3709e1c721..5ec3018f30 100644 --- a/pdns/recursordist/rec-main.hh +++ b/pdns/recursordist/rec-main.hh @@ -161,7 +161,7 @@ struct DoneRunning std::condition_variable condVar; std::atomic 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 diff --git a/pdns/recursordist/rec_channel.cc b/pdns/recursordist/rec_channel.cc index 6abab97a35..47a1832d0c 100644 --- a/pdns/recursordist/rec_channel.cc +++ b/pdns/recursordist/rec_channel.cc @@ -18,6 +18,18 @@ #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 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()); } diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index 8d398e9fb4..688b88f50e 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -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! }