Fix re-entrancy issue
authorJoohyun Kim <joohyune.kim@samsung.com>
Mon, 19 Aug 2013 05:23:01 +0000 (14:23 +0900)
committerJoohyun Kim <joohyune.kim@samsung.com>
Mon, 19 Aug 2013 05:23:01 +0000 (14:23 +0900)
Change-Id: I0306b76fdb509346876fd4151ff556a28a9a1784
Signed-off-by: Joohyun Kim <joohyune.kim@samsung.com>
src/system/FSys_SystemTimeImpl.cpp

index 3109958..199b8a0 100644 (file)
@@ -73,21 +73,20 @@ _SystemTimeImpl::GetUptime(TimeSpan& uptime)
 result
 _SystemTimeImpl::GetCurrentTime(TimeMode timeMode, DateTime& currentTime)
 {
+       struct tm gmTime;
        struct tm* pGmTime = null;
-       time_t currTime = 0;
        TimeZone timeZone;
        DateTime tempTime;
        struct timeval currentTimeVal;
 
        _LocaleManagerImpl* plm = null;
 
-       time(&currTime);
-       SysLog(NID_SYS, "Current Epoch is %lld.", currTime);
        gettimeofday(&currentTimeVal, null);
+       SysLog(NID_SYS, "Current Epoch is %lld.", currentTimeVal.tv_sec);
 
-       pGmTime = gmtime(&currTime);
-       SysTryReturnResult(NID_SYS, null != pGmTime, E_SYSTEM, "Failed to convert the time value to UTC time");
-       SysLog(NID_SYS, "Calendar time is sec:%d, min:%d, hour:%d, day:%d, mon:%d, year:%d, wday%d, year:%d, dst:%d", pGmTime->tm_sec, pGmTime->tm_min, pGmTime->tm_hour, pGmTime->tm_mday, pGmTime->tm_mon, pGmTime->tm_year, pGmTime->tm_wday, pGmTime->tm_yday, pGmTime->tm_isdst);
+       pGmTime = gmtime_r(&currentTimeVal.tv_sec, &gmTime);
+       SysTryReturnResult(NID_SYS, null != pGmTime, E_SYSTEM, "It is failed to convert the time value to UTC time");
+       SysLog(NID_SYS, "Calendar time is sec:%d, min:%d, hour:%d, day:%d, mon:%d, year:%d, wday%d, year:%d, dst:%d", gmTime.tm_sec, gmTime.tm_min, gmTime.tm_hour, gmTime.tm_mday, gmTime.tm_mon, gmTime.tm_year, gmTime.tm_wday, gmTime.tm_yday, gmTime.tm_isdst);
 
        plm = new (std::nothrow) _LocaleManagerImpl();
        SysTryReturnResult(NID_SYS, null != plm, E_SYSTEM, "_LocaleManagerImpl instance must not be null");
@@ -97,12 +96,11 @@ _SystemTimeImpl::GetCurrentTime(TimeMode timeMode, DateTime& currentTime)
        String timeZoneId = timeZone.GetId();
        int rawOffset = timeZone.GetRawOffset();
        int dstSavings = timeZone.GetDstSavings();
-       SysLog(NID_SYS, "Time zone: %S, %d, %d", timeZoneId.GetPointer(), rawOffset, dstSavings);
+       SysLog(NID_SYS, "Current time zone is %S, %d, %d", timeZoneId.GetPointer(), rawOffset, dstSavings);
 
+       tempTime.SetValue(gmTime.tm_year + 1900, gmTime.tm_mon + 1, gmTime.tm_mday, gmTime.tm_hour, gmTime.tm_min, gmTime.tm_sec, currentTimeVal.tv_usec / 1000);
 
-       tempTime.SetValue(pGmTime->tm_year + 1900, pGmTime->tm_mon + 1, pGmTime->tm_mday, pGmTime->tm_hour, pGmTime->tm_min, pGmTime->tm_sec, currentTimeVal.tv_usec / 1000);
-
-       SysLog(NID_SYS, "Original Time %d %d/%d, %d:%d:%d:%d", tempTime.GetYear(), tempTime.GetMonth(), tempTime.GetDay(), tempTime.GetHour(), tempTime.GetMinute(), tempTime.GetSecond(), tempTime.GetMillisecond());
+       SysLog(NID_SYS, "Original Time is %d %d/%d, %d:%d:%d:%d", tempTime.GetYear(), tempTime.GetMonth(), tempTime.GetDay(), tempTime.GetHour(), tempTime.GetMinute(), tempTime.GetSecond(), tempTime.GetMillisecond());
 
        switch (timeMode)
        {
@@ -122,7 +120,7 @@ _SystemTimeImpl::GetCurrentTime(TimeMode timeMode, DateTime& currentTime)
                break;
        }
 
-       SysLog(NID_SYS, "Current Time %d %d/%d, %d:%d:%d", currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(), currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
+       SysLog(NID_SYS, "Current Time is %d %d/%d, %d:%d:%d", currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(), currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
 
        return E_SUCCESS;
 }