From 64e1ddd255771e57a88a20f07dbde04a83bf0c75 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Tue, 21 Sep 2021 22:33:05 +0200 Subject: [PATCH] log: call LogPrint only once with time data samples This prevents malformed log entries caused by other threads logging concurrently. --- src/timedata.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/timedata.cpp b/src/timedata.cpp index 354092752d..f53fbe231b 100644 --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -98,11 +99,12 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample) } if (LogAcceptCategory(BCLog::NET)) { + std::string log_message{"time data samples: "}; for (const int64_t n : vSorted) { - LogPrint(BCLog::NET, "%+d ", n); /* Continued */ + log_message += strprintf("%+d ", n); } - LogPrint(BCLog::NET, "| "); /* Continued */ - LogPrint(BCLog::NET, "nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset / 60); + log_message += strprintf("| median offset = %+d (%+d minutes)", nTimeOffset, nTimeOffset / 60); + LogPrint(BCLog::NET, "%s\n", log_message); } } }