diff options
author | dahyeong.kim <dahyeong.kim@samsung.com> | 2017-07-06 20:36:37 +0900 |
---|---|---|
committer | Jiwoong Im <jiwoong.im@samsung.com> | 2017-07-07 13:16:38 +0900 |
commit | 597c3354cec4bfe03d7339ea67e8e7b69d61798d (patch) | |
tree | 0320e882586f50c78eaa348cf8e1421a7751a224 | |
parent | 42b1c8558f53e355dc7167142597c71c23fc65c1 (diff) | |
download | alarm-manager-597c3354cec4bfe03d7339ea67e8e7b69d61798d.tar.gz alarm-manager-597c3354cec4bfe03d7339ea67e8e7b69d61798d.tar.bz2 alarm-manager-597c3354cec4bfe03d7339ea67e8e7b69d61798d.zip |
Error handing when setting system-time is failed
Change-Id: I9adb45b5aa2c995045912ac48b468a87734d2f80
Signed-off-by: dahyeong.kim <dahyeong.kim@samsung.com>
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
-rw-r--r-- | alarm-manager.c | 106 |
1 files changed, 65 insertions, 41 deletions
diff --git a/alarm-manager.c b/alarm-manager.c index e083b1a..ea23074 100644 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -333,37 +333,45 @@ static void __rtc_set() int __set_time(time_t _time) { - int ret = 0; - struct timeval tv; struct tm tm, *gmtime_res; - + struct timeval tv; tv.tv_sec = _time; tv.tv_usec = 0; + char buf[1024] = {0,}; + +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; + char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; + + char *timebuf = ctime(&_time); + if (timebuf) { + timebuf[strlen(timebuf) - 1] = '\0'; /* to avoid new line */ + snprintf(log_message, sizeof(log_message), "RTC & OS =%d, %s", (int)_time, timebuf); + } +#endif gmtime_res = gmtime_r(&(tv.tv_sec), &tm); - if (!gmtime_res) - ALARM_MGR_EXCEPTION_PRINT("gmtime_r is failed. [%d]", errno); + if (!gmtime_res) { + ALARM_MGR_EXCEPTION_PRINT("gmtime_r is failed. [%s]", strerror_r(errno, buf, sizeof(buf))); + goto failure; + } - ret = settimeofday(&tv, NULL); - if (ret < 0) - ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed.[%d]", errno); + if (settimeofday(&tv, NULL) < 0) { + ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed. [%s]", strerror_r(errno, buf, sizeof(buf))); + goto failure; + } #ifdef _APPFW_FEATURE_WAKEUP_USING_RTC /* Using /dev/alarm, this function changes both OS time and RTC. */ const char *rtc0 = default_rtc; struct rtc_time _rtc_time; -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; - char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; -#endif - char buf[1024]; if (gfd < 0) { gfd = open(rtc0, O_RDWR); if (gfd < 0) { - ALARM_MGR_EXCEPTION_PRINT("Opening the /dev/alarm is failed."); + ALARM_MGR_EXCEPTION_PRINT("Opening the %s is failed. [%s]", rtc0, strerror_r(errno, buf, sizeof(buf))); perror("\t"); - return 1; + goto failure; } } @@ -378,31 +386,32 @@ int __set_time(time_t _time) _rtc_time.tm_yday = tm.tm_yday; _rtc_time.tm_isdst = tm.tm_isdst; - 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))); -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC")); -#endif + if (ioctl(gfd, RTC_SET_TIME, &_rtc_time) == -1) { + ALARM_MGR_EXCEPTION_PRINT("RTC_SET_TIME ioctl is failed. errno = %s", strerror_r(errno, buf, sizeof(buf))); perror("\t"); + goto failure; } -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - else - strncpy(log_tag, "SET RTC", strlen("SET RTC")); - - char *timebuf = ctime(&_time); - if (timebuf) { - timebuf[strlen(timebuf) - 1] = '\0'; /* to avoid new line */ - snprintf(log_message, sizeof(log_message), "RTC & OS =%d, %s", (int)_time, timebuf); + else { + goto success; } - - __save_module_log(log_tag, log_message); -#endif #else ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work."); #endif /* _APPFW_FEATURE_WAKEUP_USING_RTC */ + return 0; + +failure: +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + strncpy(log_tag, "FAIL: SET TIME", strlen("FAIL: SET TIME")); + __save_module_log(log_tag, log_message); +#endif + return -1; - return 1; +success: +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + strncpy(log_tag, "SET TIME", strlen("SET TIME")); + __save_module_log(log_tag, log_message); +#endif + return 0; } bool __alarm_clean_list() @@ -1922,7 +1931,7 @@ static void __on_system_time_external_changed(keynode_t *node, void *data) } else { if (vconf_get_dbl(VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, &diff_time) != 0) { ALARM_MGR_EXCEPTION_PRINT("Failed to get value of VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL."); - return; + goto done; } } @@ -1932,10 +1941,12 @@ static void __on_system_time_external_changed(keynode_t *node, void *data) ALARM_MGR_LOG_PRINT("diff_time is %f, New time is %s\n", diff_time, ctime(&cur_time)); ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed externally\n"); - ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", - alarm_context.c_due_time); + ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", alarm_context.c_due_time); - __set_time(cur_time); + if (__set_time(cur_time) < 0) { /* Change both OS time and RTC */ + ALARM_MGR_EXCEPTION_PRINT("Failed to set both OS time and RTC."); + goto done; + } vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, (int)diff_time); bundle *b = NULL; @@ -1946,8 +1957,9 @@ static void __on_system_time_external_changed(keynode_t *node, void *data) __alarm_update_due_time_of_all_items_in_list(diff_time); - ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n", - alarm_context.c_due_time); + ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n", alarm_context.c_due_time); + +done: _clear_scheduled_alarm_list(); _alarm_schedule(); __rtc_set(); @@ -2478,7 +2490,13 @@ gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation diff_time = difftime(time_sec, cur_time.tv_sec); } - __set_time(time_sec); /* Change both OS time and RTC */ + if (__set_time(time_sec) < 0) { /* Change both OS time and RTC */ + _clear_scheduled_alarm_list(); + _alarm_schedule(); + __rtc_set(); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ERR_ALARM_SYSTEM_FAIL)); + return true; + } ALARM_MGR_LOG_PRINT("[TIMESTAMP]Current time(%d), New time(%d)(%s), diff_time(%f)", cur_time.tv_sec, time_sec, ctime((const time_t *)&time_sec), diff_time); @@ -2529,7 +2547,13 @@ gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, nanosleep(&sleep_time, NULL); /* Wait until 0 nsec to match both OS time and RTC(sec) */ - __set_time(real_newtime); /* Change both OS time and RTC */ + if (__set_time(real_newtime) < 0) { /* Change both OS time and RTC */ + _clear_scheduled_alarm_list(); + _alarm_schedule(); + __rtc_set(); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ERR_ALARM_SYSTEM_FAIL)); + return true; + } diff_time = difftime(real_newtime, cur_time.tv_sec); ALARM_MGR_LOG_PRINT("[TIMESTAMP]Current time(%d.%09d), New time(%d.%09d), Real Newtime(%d), diff_time(%f)", |