fix system time setting in tv profile 86/90086/2 accepted/tizen/common/20160928.164447 submit/tizen/20160928.084653
authorJiwoong Im <jiwoong.im@samsung.com>
Wed, 28 Sep 2016 08:32:48 +0000 (17:32 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Wed, 28 Sep 2016 08:36:50 +0000 (17:36 +0900)
Change-Id: I5ad368f964f33cc46bfc7cc86306db38a8a7a813
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
alarm-manager.c

index 891ae34..8258c8d 100644 (file)
@@ -266,13 +266,13 @@ static void __rtc_set()
 
 int __set_time(time_t _time)
 {
+       int ret = 0;
+       struct timeval tv;
+       struct tm tm, *gmtime_res;
 #ifdef _APPFW_FEATURE_WAKEUP_USING_RTC
        /* Using /dev/alarm, this function changes both OS time and RTC. */
-       int ret = 0;
        const char *rtc0 = default_rtc;
        struct rtc_time _rtc_time;
-       struct timeval tv;
-       struct tm tm, *gmtime_res;
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
@@ -288,13 +288,6 @@ int __set_time(time_t _time)
                }
        }
 
-       tv.tv_sec = _time;
-       tv.tv_usec = 0;
-
-       gmtime_res = gmtime_r(&(tv.tv_sec), &tm);
-       if (!gmtime_res)
-               ALARM_MGR_EXCEPTION_PRINT("gmtime_r is failed. [%d]", errno);
-
        memset(&_rtc_time, 0, sizeof(_rtc_time));
        _rtc_time.tm_sec = tm.tm_sec;
        _rtc_time.tm_min = tm.tm_min;
@@ -306,11 +299,6 @@ int __set_time(time_t _time)
        _rtc_time.tm_yday = tm.tm_yday;
        _rtc_time.tm_isdst = tm.tm_isdst;
 
-
-       ret = settimeofday(&tv, NULL);
-       if (ret < 0)
-               ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed.[%d]", errno);
-
        ret = ioctl(gfd, RTC_SET_TIME, &_rtc_time);
        if (ret == -1) {
                ALARM_MGR_EXCEPTION_PRINT("ALARM_SET_RTC ioctl is failed. errno = %s", strerror_r(errno, buf, sizeof(buf)));
@@ -334,6 +322,17 @@ int __set_time(time_t _time)
 #else
        ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
 #endif /* _APPFW_FEATURE_WAKEUP_USING_RTC */
+       tv.tv_sec = _time;
+       tv.tv_usec = 0;
+
+       gmtime_res = gmtime_r(&(tv.tv_sec), &tm);
+       if (!gmtime_res)
+               ALARM_MGR_EXCEPTION_PRINT("gmtime_r is failed. [%d]", errno);
+
+       ret = settimeofday(&tv, NULL);
+       if (ret < 0)
+               ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed.[%d]", errno);
+
        return 1;
 }