summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInkyun Kil <inkyun.kil@samsung.com>2019-07-23 09:50:33 +0900
committerInkyun Kil <inkyun.kil@samsung.com>2019-08-20 08:51:16 +0900
commit58d54ae60baf6e4f15fc81d5b82023d9c2b4a01d (patch)
tree299de5f57453fb25d178e6e111f7412f590ba95c
parent98a517fbccea2b51de8d1c8b9efc811e0d8121d4 (diff)
downloadalarm-manager-58d54ae60baf6e4f15fc81d5b82023d9c2b4a01d.tar.gz
alarm-manager-58d54ae60baf6e4f15fc81d5b82023d9c2b4a01d.tar.bz2
alarm-manager-58d54ae60baf6e4f15fc81d5b82023d9c2b4a01d.zip
Check return codes
- Remove meaningless return codes - Check return value Change-Id: Ifff8038f5b70acc3ba11ec0ea5b8f05e80339ddf Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
-rwxr-xr-xinclude/alarm-internal.h15
-rw-r--r--server/alarm-manager-db.c4
-rw-r--r--server/alarm-manager-schedule.c48
-rw-r--r--server/alarm-manager-timer.c15
-rwxr-xr-xserver/alarm-manager.c392
5 files changed, 237 insertions, 237 deletions
diff --git a/include/alarm-internal.h b/include/alarm-internal.h
index 7b79486..9331667 100755
--- a/include/alarm-internal.h
+++ b/include/alarm-internal.h
@@ -162,14 +162,13 @@ typedef struct _bg_category_cb_info_t {
void _release_alarm_info_t();
-time_t _alarm_next_duetime(__alarm_info_t *alarm_info);
-bool _alarm_schedule();
-bool _clear_scheduled_alarm_list();
-bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
-
-bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time);
-bool _alarm_disable_timer(__alarm_server_context_t alarm_context);
-bool _init_scheduled_alarm_list();
+void _alarm_set_next_duetime(__alarm_info_t *alarm_info);
+void _alarm_schedule();
+void _clear_scheduled_alarm_list();
+void _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
+
+void _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time);
+void _alarm_disable_timer(__alarm_server_context_t alarm_context);
void _alarm_initialize();
time_t _get_periodic_alarm_standard_time(void);
diff --git a/server/alarm-manager-db.c b/server/alarm-manager-db.c
index 52ee224..b92f0cc 100644
--- a/server/alarm-manager-db.c
+++ b/server/alarm-manager-db.c
@@ -298,11 +298,11 @@ void _load_alarms_from_db()
free(noti);
if (is_disabled) {
- _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
g_disabled_alarm_list = g_slist_append(g_disabled_alarm_list, __alarm_info);
ALARM_MGR_EXCEPTION_PRINT("Save alarm_id[%d] caller[%s] callee[%s]", __alarm_info->alarm_id, caller_pkgid, callee_pkgid);
} else {
- _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info);
}
}
diff --git a/server/alarm-manager-schedule.c b/server/alarm-manager-schedule.c
index 8f20515..171db5b 100644
--- a/server/alarm-manager-schedule.c
+++ b/server/alarm-manager-schedule.c
@@ -37,30 +37,22 @@ static time_t __alarm_next_duetime_annually(__alarm_info_t *__alarm_info);
static time_t __alarm_next_duetime_monthly(__alarm_info_t *__alarm_info);
static time_t __alarm_next_duetime_weekly(__alarm_info_t *__alarm_info);
static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time);
-bool _alarm_schedule(void);
-bool _clear_scheduled_alarm_list()
+void _clear_scheduled_alarm_list()
{
g_slist_free_full(g_scheduled_alarm_list, free);
g_scheduled_alarm_list = NULL;
-
- return true;
-}
-
-bool _init_scheduled_alarm_list()
-{
- _clear_scheduled_alarm_list();
-
- return true;
}
-bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info)
+void _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info)
{
__scheduled_alarm_t *alarm = NULL;
alarm = (__scheduled_alarm_t *)g_malloc(sizeof(__scheduled_alarm_t));
- if (alarm == NULL)
- return false;
+ if (alarm == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("Out of memory");
+ return;
+ }
alarm->used = true;
alarm->alarm_id = __alarm_info->alarm_id;
@@ -71,8 +63,6 @@ bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info)
__FUNCTION__, alarm->uid, alarm->__alarm_info->app_service_name);
g_scheduled_alarm_list = g_slist_append(g_scheduled_alarm_list, alarm);
-
- return true;
}
bool _remove_from_scheduled_alarm_list(uid_t uid, alarm_id_t alarm_id)
@@ -402,7 +392,7 @@ static time_t __alarm_next_duetime_weekly(__alarm_info_t *__alarm_info)
return due_time;
}
-time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
+void _alarm_set_next_duetime(__alarm_info_t *__alarm_info)
{
int is_dst = 0;
time_t current_time = 0;
@@ -433,7 +423,8 @@ time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
} else {
ALARM_MGR_EXCEPTION_PRINT("repeat mode(%d) is wrong\n",
mode->repeat);
- return 0;
+ __alarm_info->due_time = due_time;
+ return;
}
if (mode->repeat != ALARM_REPEAT_MODE_WEEKLY && mode->repeat != ALARM_REPEAT_MODE_ONCE) {
@@ -454,11 +445,10 @@ time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
if (__alarm_info->end != 0 && __alarm_info->end < due_time) {
ALARM_MGR_LOG_PRINT("due time > end time");
__alarm_info->due_time = 0;
- return 0;
+ return;
}
- __alarm_info->due_time = due_time;
- return due_time;
+ __alarm_info->due_time = due_time;
}
static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time)
@@ -497,22 +487,23 @@ static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time)
min_time = due_time;
}
+ if (min_time == -1) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server][schedule]: There is no alarm to be scheduled.");
+ return false;
+ }
+
*min_due_time = min_time;
return true;
}
-bool _alarm_schedule()
+void _alarm_schedule()
{
time_t due_time = 0;
time_t min_time = 0;
GSList *iter = NULL;
__alarm_info_t *entry = NULL;
- __find_next_alarm_to_be_scheduled(&min_time);
-
- if (min_time == -1) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server][schedule]: There is no alarm to be scheduled.");
- } else {
+ if (__find_next_alarm_to_be_scheduled(&min_time)) {
for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
entry = (__alarm_info_t *)iter->data;
due_time = entry->due_time;
@@ -520,8 +511,7 @@ bool _alarm_schedule()
if (due_time == min_time)
_add_to_scheduled_alarm_list(entry);
}
+
_alarm_set_timer(&alarm_context, alarm_context.timer, min_time);
}
-
- return true;
}
diff --git a/server/alarm-manager-timer.c b/server/alarm-manager-timer.c
index cf86ba2..498a8cb 100644
--- a/server/alarm-manager-timer.c
+++ b/server/alarm-manager-timer.c
@@ -28,7 +28,7 @@
extern bool g_dummy_timer_is_set;
-bool _alarm_disable_timer(__alarm_server_context_t alarm_context)
+void _alarm_disable_timer(__alarm_server_context_t alarm_context)
{
struct itimerspec time_spec;
@@ -36,15 +36,11 @@ bool _alarm_disable_timer(__alarm_server_context_t alarm_context)
time_spec.it_value.tv_nsec = 0;
time_spec.it_interval.tv_sec = time_spec.it_interval.tv_nsec = 0;
- if (timerfd_settime(alarm_context.timer, 0, &time_spec, NULL) < 0) {
- perror("disable timer has failed\n");
- return false;
- }
-
- return true;
+ if (timerfd_settime(alarm_context.timer, 0, &time_spec, NULL) < 0)
+ ALARM_MGR_EXCEPTION_PRINT("timerfd_settime has failed : errno(%d).", errno);
}
-bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time)
+void _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time)
{
struct itimerspec time_spec;
time_t current_time;
@@ -79,10 +75,9 @@ bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t
if (interval > 0 && timerfd_settime(timer, TFD_TIMER_ABSTIME, &time_spec, NULL) != 0) {
ALARM_MGR_EXCEPTION_PRINT("set timer has failed : timer(%d), due_time(%ld) , errno(%d).", timer, due_time, errno);
- return false;
}
+
/* we set c_due_time to due_time due to allow newly created alarm can
be schedlued when its interval is less than the current alarm */
alarm_context->c_due_time = due_time;
- return true;
}
diff --git a/server/alarm-manager.c b/server/alarm-manager.c
index 3d41f07..ed9e489 100755
--- a/server/alarm-manager.c
+++ b/server/alarm-manager.c
@@ -108,9 +108,9 @@ static __alarm_info_t *__alarm_update_in_list(uid_t uid, alarm_id_t alarm_id,
alarm_info_t *alarm_info, int update_flag, int *error_code);
static bool __alarm_remove_from_list(uid_t uid, alarm_id_t alarm_id,
int *error_code);
-static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
+static void __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
__alarm_info_t *__alarm_info);
-static bool __alarm_update_due_time_of_all_items_in_list(double diff_time);
+static void __alarm_update_due_time_of_all_items_in_list(double diff_time);
static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t uid,
int pid, periodic_method_e method, long requested_interval, int is_ref,
char *app_service_name, char *app_service_name_mod,
@@ -128,18 +128,16 @@ static void __on_system_time_external_changed(keynode_t *node, void *data);
static void __initialize_timer();
static void __initialize_alarm_list();
static void __initialize_scheduled_alarm_list();
-static bool __initialize_noti();
+static void __initialize_noti();
void _release_alarm_info_t(__alarm_info_t *entry);
static notification_h __get_notification(guchar *data, int datalen);
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
static void __initialize_module_log(void);
-static bool __save_module_log(const char *tag, const char *messgae);
+static void __save_module_log(const char *tag, const char *messgae);
#endif
-int __set_time(time_t _time);
-
static bool __get_caller_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid)
{
char caller_appid[MAX_APP_ID_LEN] = {0,};
@@ -357,7 +355,7 @@ static void __rtc_set()
return;
}
-int __set_time(time_t _time)
+static bool __set_time(time_t _time)
{
int ret = 0;
struct timeval tv;
@@ -367,28 +365,37 @@ int __set_time(time_t _time)
tv.tv_usec = 0;
gmtime_res = gmtime_r(&(tv.tv_sec), &tm);
- if (!gmtime_res)
+ if (!gmtime_res) {
ALARM_MGR_EXCEPTION_PRINT("gmtime_r is failed. [%d]", errno);
+ return false;
+ }
ret = settimeofday(&tv, NULL);
- if (ret < 0)
+ if (ret < 0) {
ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed.[%d]", errno);
+ return false;
+ }
if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
const char *rtc0 = default_rtc;
struct rtc_time _rtc_time;
+ char buf[1024];
#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
- char buf[1024];
if (gfd < 0) {
gfd = open(rtc0, O_RDWR);
if (gfd < 0) {
ALARM_MGR_EXCEPTION_PRINT("Opening the /dev/rtc is failed.");
- perror("\t");
- return 1;
+ return false;
}
}
@@ -408,26 +415,21 @@ int __set_time(time_t _time)
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", sizeof(log_tag) - 1);
+ __save_module_log(log_tag, log_message);
#endif
- perror("\t");
- }
+ } else {
+ ALARM_MGR_LOG_PRINT("ALARM_SET_RTC ioctl is succeed. [%d]", (int)_time);
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- else
strncpy(log_tag, "SET RTC", sizeof(log_tag) - 1);
-
- 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);
- }
-
- __save_module_log(log_tag, log_message);
+ __save_module_log(log_tag, log_message);
#endif
+ return false;
+ }
} else {
ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
}
- return 1;
+ return true;
}
bool __alarm_clean_list()
@@ -610,15 +612,16 @@ static bool __alarm_remove_from_list(uid_t uid, alarm_id_t alarm_id,
ALARM_MGR_LOG_PRINT("[alarm-server]:Remove alarm id(%d)", entry->alarm_id);
- if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
- _delete_alarms(alarm_id);
+ if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
+ if (!_delete_alarms(alarm_id))
+ break;
+ }
alarm_context.alarms = g_slist_remove(alarm_context.alarms, iter->data);
_release_alarm_info_t(entry);
found = true;
break;
}
-
}
ALARM_MGR_LOG_PRINT("[alarm-server]: after del\n");
@@ -632,7 +635,7 @@ static bool __alarm_remove_from_list(uid_t uid, alarm_id_t alarm_id,
return true;
}
-static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
+static void __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
__alarm_info_t *__alarm_info)
{
alarm_date_t *start = &alarm_info->start;
@@ -672,11 +675,9 @@ static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
} else {
__alarm_info->end = 0;
}
-
- return true;
}
-static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
+static void __alarm_update_due_time_of_all_items_in_list(double diff_time)
{
time_t current_time;
time_t min_time = -1;
@@ -725,7 +726,7 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
}
}
}
- _alarm_next_duetime(entry);
+ _alarm_set_next_duetime(entry);
}
time(&current_time);
@@ -758,7 +759,6 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
alarm_context.c_due_time = min_time;
g_idle_add(_update_relative_alarms, NULL);
- return true;
}
static void __set_caller_info(bundle *b, uid_t uid,
@@ -783,7 +783,6 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
long requested_interval, uid_t uid, int pid, char *bundle_data, int *error_code)
{
time_t current_time;
- time_t due_time;
struct tm ts_ret;
char due_time_r[100] = { 0 };
char app_name[MAX_APP_ID_LEN] = { 0 };
@@ -854,38 +853,41 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
alarm_context.c_due_time = -1;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
__alarm_add_to_list(__alarm_info);
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
- "due_time is 0, alarm(%d) \n", *alarm_id);
+ "__alarm_info->due_time is 0, alarm(%d) \n", *alarm_id);
return true;
- } else if (current_time == due_time) {
+ } else if (current_time == __alarm_info->due_time) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
- "current_time(%ld) is same as due_time(%ld)", current_time,
- due_time);
+ "current_time(%ld) is same as __alarm_info->due_time(%ld)", current_time,
+ __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list\n", due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.\
+ [Due time=%ld, Current Time=%ld]!!!Do not add to schedule list\n",
+ __alarm_info->due_time, current_time);
return true;
} else {
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
SECURE_LOGD("[alarm-server]:Create a new alarm: "
- "alarm(%d) due_time(%s)", *alarm_id,
+ "alarm(%d) __alarm_info->due_time(%s)", *alarm_id,
due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld),\
+ __alarm_info->due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
_clear_scheduled_alarm_list();
_add_to_scheduled_alarm_list(__alarm_info);
- _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
__rtc_set();
- } else if (due_time == alarm_context.c_due_time) {
+ } else if (__alarm_info->due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
}
@@ -899,9 +901,10 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t
int *error_code)
{
time_t current_time;
- time_t due_time;
char unique_name[MAX_APP_ID_LEN] = { 0 };
bool caller_is_app = false;
+ char due_time_r[100] = { 0 };
+ struct tm ts_ret;
__alarm_info_t *__alarm_info = NULL;
@@ -961,37 +964,37 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t
alarm_context.c_due_time = -1;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
__alarm_add_to_list(__alarm_info);
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id);
return true;
- } else if (current_time == due_time) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld) is same as due_time(%ld).",
- current_time, due_time);
+ } else if (current_time == __alarm_info->due_time) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld)\
+ is same as due_time(%ld).", current_time, __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list.",
- due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld,\
+ Current Time=%ld]!!!Do not add to schedule list.",
+ __alarm_info->due_time, current_time);
return true;
} else {
- char due_time_r[100] = { 0 };
- struct tm ts_ret;
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
- SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)", *alarm_id, due_time_r);
+ SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)",
+ *alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
_clear_scheduled_alarm_list();
_add_to_scheduled_alarm_list(__alarm_info);
- _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
__rtc_set();
- } else if (due_time == alarm_context.c_due_time) {
+ } else if (__alarm_info->due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
}
@@ -1048,7 +1051,6 @@ static bool __alarm_create_noti(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
long requested_interval, uid_t uid, int pid, char *noti_data, int *error_code)
{
time_t current_time;
- time_t due_time;
struct tm ts_ret;
char due_time_r[100] = { 0 };
char app_name[MAX_APP_ID_LEN] = { 0 };
@@ -1114,35 +1116,36 @@ static bool __alarm_create_noti(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
alarm_context.c_due_time = -1;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
__alarm_add_to_list(__alarm_info);
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id);
return true;
- } else if (current_time == due_time) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld) is same as due_time(%ld).",
- current_time, due_time);
+ } else if (current_time == __alarm_info->due_time) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld)\
+ is same as due_time(%ld).", current_time, __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list.",
- due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld,\
+ Current Time=%ld]!!!Do not add to schedule list.",
+ __alarm_info->due_time, current_time);
return true;
} else {
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)", *alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
_clear_scheduled_alarm_list();
_add_to_scheduled_alarm_list(__alarm_info);
- _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
__rtc_set();
- } else if (due_time == alarm_context.c_due_time) {
+ } else if (__alarm_info->due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
}
@@ -1153,8 +1156,8 @@ static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
alarm_info_t *alarm_info, int update_flag, int *error_code)
{
time_t current_time;
- time_t due_time;
-
+ char due_time_r[100] = { 0 };
+ struct tm ts_ret;
__alarm_info_t *__alarm_info = NULL;
bool result = false;
@@ -1174,10 +1177,9 @@ static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
return false;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
result = _remove_from_scheduled_alarm_list(uid, alarm_id);
-
if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
/*there is no scheduled alarm */
_alarm_disable_timer(alarm_context);
@@ -1187,46 +1189,46 @@ static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
__rtc_set();
- if (due_time == 0)
+ if (__alarm_info->due_time == 0)
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: due_time is 0.");
return true;
}
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
"due_time is 0, alarm(%d)\n", alarm_id);
return true;
- } else if (current_time == due_time) {
+ } else if (current_time == __alarm_info->due_time) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
"current_time(%ld) is same as due_time(%ld)", current_time,
- due_time);
+ __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list\n", due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld,\
+ Current Time=%ld]!!!Do not add to schedule list\n",
+ __alarm_info->due_time, current_time);
return true;
} else {
- char due_time_r[100] = { 0 };
- struct tm ts_ret;
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
SECURE_LOGD("[alarm-server]:Update alarm: alarm(%d) "
"due_time(%s)\n", alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
_clear_scheduled_alarm_list();
_add_to_scheduled_alarm_list(__alarm_info);
- _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
- "(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
- } else if (due_time == alarm_context.c_due_time) {
+ "(%ld), due_time(%ld)", alarm_context.c_due_time, __alarm_info->due_time);
+ } else if (__alarm_info->due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
ALARM_MGR_LOG_PRINT("[alarm-server2]:alarm_context.c_due_time "
- "(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ "(%ld), due_time(%ld)", alarm_context.c_due_time, __alarm_info->due_time);
}
__rtc_set();
@@ -1642,7 +1644,7 @@ static void __alarm_expired()
if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE)
__alarm_remove_from_list(__alarm_info->uid, alarm_id, NULL);
else
- _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
}
done:
@@ -1731,7 +1733,13 @@ static void __on_system_time_external_changed(keynode_t *node, void *data)
ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %ld\n",
alarm_context.c_due_time);
- __set_time(cur_time);
+ if (!__set_time(cur_time)) { /* Change both OS time and RTC */
+ ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
+ _clear_scheduled_alarm_list();
+ _alarm_schedule();
+ __rtc_set();
+ return;
+ }
vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, (int)diff_time);
bundle *b = NULL;
@@ -1759,7 +1767,6 @@ static int __on_app_enable_cb(uid_t target_uid, int req_id,
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
- int duetime = 0;
bool is_restored = false;
if (key && strncmp(key, "end", 3) == 0 && val && strncmp(val, "ok", 2) == 0) {
@@ -1769,8 +1776,9 @@ static int __on_app_enable_cb(uid_t target_uid, int req_id,
gs_iter = g_slist_next(gs_iter);
if (strncmp(appid, entry->app_unique_name, strlen(appid)) == 0) {
- duetime = _alarm_next_duetime(entry);
- SECURE_LOGD("Restore alarm_id(%d) duetime(%d) appid(%s)", entry->alarm_id, duetime, appid);
+ _alarm_set_next_duetime(entry);
+ SECURE_LOGD("Restore alarm_id(%d) duetime(%d) appid(%s)",
+ entry->alarm_id, (int)(entry->due_time), appid);
alarm_context.alarms = g_slist_append(alarm_context.alarms, entry);
g_disabled_alarm_list = g_slist_remove(g_disabled_alarm_list, entry);
@@ -1901,7 +1909,7 @@ static void __initialize_module_log(void)
return;
}
-static bool __save_module_log(const char *tag, const char *message)
+static void __save_module_log(const char *tag, const char *message)
{
char buffer[ALARMMGR_LOG_BUFFER_STRING_SIZE] = {0,};
time_t now;
@@ -1909,7 +1917,7 @@ static bool __save_module_log(const char *tag, const char *message)
if (log_fd == -1) {
ALARM_MGR_EXCEPTION_PRINT("The file is not ready.");
- return false;
+ return;
}
if (log_index != 0)
@@ -1923,13 +1931,11 @@ static bool __save_module_log(const char *tag, const char *message)
int ret = write(log_fd, buffer, strlen(buffer));
if (ret < 0) {
ALARM_MGR_EXCEPTION_PRINT("Writing the alarmmgr log is failed. err: %s", strerror_r(errno, buf, sizeof(buf)));
- return false;
+ return;
}
if (++log_index >= ALARMMGR_LOG_BUFFER_SIZE)
log_index = 0;
-
- return true;
}
#endif /* _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG */
@@ -2064,83 +2070,82 @@ static int __check_modifiable(uid_t uid, pid_t pid, int alarm_id)
int alarm_manager_alarm_set_rtc_time(GVariant *parameters)
{
-/* Indentation ingored to help understand the patch. */
-if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
- const char *rtc = default_rtc;
- struct rtc_wkalrm rtc_wkalarm;
- int retval = 0;
- struct tm tm, *alarm_tm = NULL;
+ if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
+ const char *rtc = default_rtc;
+ struct rtc_wkalrm rtc_wkalarm;
+ int retval = 0;
+ struct tm tm, *alarm_tm = NULL;
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
- char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
#endif
- /*extract day of the week, day in the year & daylight saving time from system*/
- time_t current_time;
- char buf[1024];
- int year, mon, day, hour, min, sec;
- int return_code = ALARMMGR_RESULT_SUCCESS;
+ /*extract day of the week, day in the year & daylight saving time from system*/
+ time_t current_time;
+ char buf[1024];
+ int year, mon, day, hour, min, sec;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
- g_variant_get(parameters, "(iiiiii)", &year, &mon, &day, &hour, &min, &sec);
+ g_variant_get(parameters, "(iiiiii)", &year, &mon, &day, &hour, &min, &sec);
- current_time = time(NULL);
- alarm_tm = gmtime_r(&current_time, &tm);
- if (alarm_tm == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("alarm_tm is NULL");
- return ERR_ALARM_SYSTEM_FAIL;
- }
+ current_time = time(NULL);
+ alarm_tm = gmtime_r(&current_time, &tm);
+ if (alarm_tm == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("alarm_tm is NULL");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
- alarm_tm->tm_year = year;
- alarm_tm->tm_mon = mon;
- alarm_tm->tm_mday = day;
- alarm_tm->tm_hour = hour;
- alarm_tm->tm_min = min;
- alarm_tm->tm_sec = sec;
+ alarm_tm->tm_year = year;
+ alarm_tm->tm_mon = mon;
+ alarm_tm->tm_mday = day;
+ alarm_tm->tm_hour = hour;
+ alarm_tm->tm_min = min;
+ alarm_tm->tm_sec = sec;
- /*convert to calendar time representation*/
- time_t rtc_time = mktime(alarm_tm);
+ /*convert to calendar time representation*/
+ time_t rtc_time = mktime(alarm_tm);
- if (gfd < 0) {
- gfd = open(rtc, O_RDWR);
if (gfd < 0) {
- ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
- return ERR_ALARM_SYSTEM_FAIL;
+ gfd = open(rtc, O_RDWR);
+ if (gfd < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
}
- }
- rtc_wkalarm.enabled = 1;
- rtc_wkalarm.time.tm_year = year;
- rtc_wkalarm.time.tm_mon = mon;
- rtc_wkalarm.time.tm_mday = day;
- rtc_wkalarm.time.tm_hour = hour;
- rtc_wkalarm.time.tm_min = min;
- rtc_wkalarm.time.tm_sec = sec;
+ rtc_wkalarm.enabled = 1;
+ rtc_wkalarm.time.tm_year = year;
+ rtc_wkalarm.time.tm_mon = mon;
+ rtc_wkalarm.time.tm_mday = day;
+ rtc_wkalarm.time.tm_hour = hour;
+ rtc_wkalarm.time.tm_min = min;
+ rtc_wkalarm.time.tm_sec = sec;
- retval = ioctl(gfd, RTC_WKALM_SET, &rtc_wkalarm);
- if (retval == -1) {
- if (errno == ENOTTY)
- ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
+ retval = ioctl(gfd, RTC_WKALM_SET, &rtc_wkalarm);
+ if (retval == -1) {
+ if (errno == ENOTTY)
+ ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
- ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror_r(errno, buf, sizeof(buf)));
- return_code = ERR_ALARM_SYSTEM_FAIL;
+ ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror_r(errno, buf, sizeof(buf)));
+ return_code = ERR_ALARM_SYSTEM_FAIL;
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- strncpy(log_tag, "FAIL: SET RTC", sizeof(log_tag) - 1);
+ strncpy(log_tag, "FAIL: SET RTC", sizeof(log_tag) - 1);
#endif
- } else {
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
+ } else {
+ ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- strncpy(log_tag, "SET RTC", sizeof(log_tag) - 1);
+ strncpy(log_tag, "SET RTC", sizeof(log_tag) - 1);
#endif
- }
+ }
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- snprintf(log_message, sizeof(log_message), "wakeup rtc time: %d, %s", (int)rtc_time, ctime(&rtc_time));
- __save_module_log(log_tag, log_message);
+ snprintf(log_message, sizeof(log_message), "wakeup rtc time: %d, %s", (int)rtc_time, ctime(&rtc_time));
+ __save_module_log(log_tag, log_message);
#endif
- return return_code;
-} else {
- ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
- return ERR_ALARM_SYSTEM_FAIL;
-}
+ return return_code;
+ } else {
+ ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
}
static int accrue_msec = 0; /* To check a millisecond part of current time at changing the system time(sec) */
@@ -2166,7 +2171,14 @@ int alarm_manager_alarm_set_time(GVariant* parameters)
diff_time = difftime(time_sec, cur_time.tv_sec);
}
- __set_time(time_sec); /* Change both OS time and RTC */
+ if (!__set_time(time_sec)) { /* Change both OS time and RTC */
+ ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
+ _clear_scheduled_alarm_list();
+ _alarm_schedule();
+ __rtc_set();
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+
ALARM_MGR_LOG_PRINT("[TIMESTAMP]Current time(%ld), New time(%d)(%s), diff_time(%f)",
cur_time.tv_sec, time_sec, ctime((const time_t *)&time_sec), diff_time);
@@ -2217,7 +2229,13 @@ int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters)
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)) { /* Change both OS time and RTC */
+ ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
+ _clear_scheduled_alarm_list();
+ _alarm_schedule();
+ __rtc_set();
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
diff_time = difftime(real_newtime, cur_time.tv_sec);
ALARM_MGR_LOG_PRINT("[TIMESTAMP]Current time(%ld.%09ld), New time(%d.%09d), Real Newtime(%d), diff_time(%f)",
@@ -2332,16 +2350,14 @@ int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid
if (b == NULL) {
int ret_bundle = get_last_result();
ALARM_MGR_EXCEPTION_PRINT("Failed to decode bundle_data[Error:%d]\n", ret_bundle);
- return_code = ERR_ALARM_SYSTEM_FAIL;
- return return_code;
+ return ERR_ALARM_SYSTEM_FAIL;
} else {
callee_appid = appsvc_get_appid(b);
if (_compare_api_version(&result, pid, uid) < 0) {
ALARM_MGR_EXCEPTION_PRINT("Unable to check api version\n");
- return_code = ERR_ALARM_SYSTEM_FAIL;
bundle_free(b);
- return return_code;
+ return ERR_ALARM_SYSTEM_FAIL;
}
if (result < 0) {
@@ -2350,9 +2366,8 @@ int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid
} else { /* Since 2.4 */
if (!_is_permitted(callee_appid, alarm_type, uid)) {
ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", callee_appid);
- return_code = ERR_ALARM_NOT_PERMITTED_APP;
bundle_free(b);
- return return_code;
+ return ERR_ALARM_NOT_PERMITTED_APP;
}
}
@@ -3022,7 +3037,6 @@ int alarm_manager_alarm_get_next_duetime(GVariant *parameters, uid_t uid, int *d
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
__alarm_info_t *find_item = NULL;
- time_t _duetime = 0;
int alarm_id;
if (uid < 0)
@@ -3044,10 +3058,10 @@ int alarm_manager_alarm_get_next_duetime(GVariant *parameters, uid_t uid, int *d
return ERR_ALARM_INVALID_ID;
}
- _duetime = _alarm_next_duetime(find_item);
- ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&_duetime));
+ _alarm_set_next_duetime(find_item);
+ ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&(find_item->due_time)));
- *duetime = (int)_duetime;
+ *duetime = (int)(find_item->due_time);
return ALARMMGR_RESULT_SUCCESS;
}
@@ -3243,10 +3257,10 @@ static void __initialize_alarm_list()
static void __initialize_scheduled_alarm_list()
{
- _init_scheduled_alarm_list();
+ _clear_scheduled_alarm_list();
}
-static bool __initialize_noti()
+static void __initialize_noti()
{
/* VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL is set by OSP app-service. */
if (vconf_notify_key_changed
@@ -3264,7 +3278,6 @@ static bool __initialize_noti()
pkgmgr_client_set_status_type(pc, PKGMGR_CLIENT_STATUS_DISABLE_APP);
pkgmgr_client_listen_app_status(pc, __on_app_disable_cb, NULL);
- return true;
}
void _alarm_initialize()
@@ -3292,13 +3305,16 @@ void _alarm_initialize()
#endif
__initialize_scheduled_alarm_list();
- _initialize_db();
+ if (_initialize_db() == false) {
+ ALARM_MGR_EXCEPTION_PRINT("_initialize_db failed, "
+ "alarm cannot be stored to database.\n");
+ }
__initialize_alarm_list();
__initialize_noti();
if (!caller_appid_cache_table) {
- caller_appid_cache_table = g_hash_table_new_full(g_int_hash, g_int_equal,
- NULL, __free_cached_value);
+ caller_appid_cache_table = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal, NULL, __free_cached_value);
}
}