]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Tsan complained about strftime(), it manulipates locale and/or tz info.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 17 May 2022 12:37:03 +0000 (14:37 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 18 May 2022 09:57:39 +0000 (11:57 +0200)
So guard if needed.

pdns/recursordist/rec-main.cc

index b00a0af1fc334c508703cb61efb10bc049bf899b..be46da934b6396b2bdcb008cdf21a3f6b9c65856 100644 (file)
@@ -827,8 +827,14 @@ static std::string s_timestampFormat = "%s";
 
 static const char* toTimestampStringMilli(const struct timeval& tv, char* buf, size_t sz)
 {
-  struct tm tm;
-  size_t len = strftime(buf, sz, s_timestampFormat.c_str(), localtime_r(&tv.tv_sec, &tm));
+  size_t len = 0;
+  if (s_timestampFormat != "%s") {
+    // strftime is not thread safe, it can access locale information
+    static std::mutex m;
+    auto lock = std::lock_guard(m);
+    struct tm tm;
+    len = strftime(buf, sz, s_timestampFormat.c_str(), localtime_r(&tv.tv_sec, &tm));
+  }
   if (len == 0) {
     len = snprintf(buf, sz, "%lld", static_cast<long long>(tv.tv_sec));
   }