Change std::localtime to localtime_r in file-sink.cpp
[platform/core/security/ode.git] / server / file-sink.cpp
index 50b86d1..a6d1a93 100644 (file)
@@ -85,7 +85,21 @@ void FileLogSink::write(const std::string &message)
        resize();
 
        auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
-       std::tm tm = *std::localtime(&now);
+       std::tm tm = {
+               .tm_sec = 0,
+               .tm_min = 0,
+               .tm_hour = 0,
+               .tm_mday = 1,
+               .tm_mon = 1,
+               .tm_year = 0,
+               .tm_wday = 0,
+               .tm_yday = 0,
+               .tm_isdst = 1,
+       };
+
+       if (::localtime_r(&now, &tm) == nullptr)
+               std::cerr << "Failed to get local time" << std::endl;
+
        std::string log("[" + std::to_string(tm.tm_hour)
                        + ":"
                        + std::to_string(tm.tm_min)