From c8007266bafdc8dd37b1b6be2f1f59f4520dd712 Mon Sep 17 00:00:00 2001 From: Eduardo Gonzalez Date: Fri, 21 Aug 2026 10:41:54 +0200 Subject: [PATCH] gconnman_clock.cpp: Use thread-safe std::tm Use localtime_r and private tm struct. Fixes #34 Signed-off-by: Eduardo Gonzalez --- src/dbus/gconnman_clock.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dbus/gconnman_clock.cpp b/src/dbus/gconnman_clock.cpp index 45ee737..a58a504 100644 --- a/src/dbus/gconnman_clock.cpp +++ b/src/dbus/gconnman_clock.cpp @@ -98,10 +98,13 @@ void Clock::setTimeServers(const std::vector& servers, auto operator<<(std::ostream& ost, const ClockProperties& obj) -> std::ostream& { - ost << TIME_STR << ": " << obj.time_ << " ("; + ost << TIME_STR << ": " << obj.time_; const auto time_value = static_cast(obj.time_); - ost << std::put_time(std::localtime(&time_value), "%Y-%m-%d %H:%M:%S") - << ")\n"; + std::tm local_time{}; + if (localtime_r(&time_value, &local_time) != nullptr) { + ost << " (" << std::put_time(&local_time, "%Y-%m-%d %H:%M:%S") << ")"; + } + ost << '\n'; ost << TIMEUPDATES_STR << ": " << TIME_UPDATE_MAP.toString(obj.time_updates_) << '\n'; ost << TIMEZONE_STR << ": " << obj.timezone_ << '\n';