Change std::localtime to localtime_r in file-sink.cpp 12/196712/6
authorseolheui, kim <s414.kim@samsung.com>
Fri, 4 Jan 2019 01:03:44 +0000 (10:03 +0900)
committerseolheui, kim <s414.kim@samsung.com>
Fri, 4 Jan 2019 06:38:15 +0000 (15:38 +0900)
- To guarantee of thread-safe

Change-Id: I707173361df0d5f0b2d901d30d4f588178301575
Signed-off-by: seolheui, kim <s414.kim@samsung.com>
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)