diff options
author | Inkyun Kil <inkyun.kil@samsung.com> | 2019-08-30 10:58:57 +0900 |
---|---|---|
committer | Inkyun Kil <inkyun.kil@samsung.com> | 2019-09-06 09:56:28 +0900 |
commit | 80b42d375a6d70833b1e068cebafe80ca9a859f6 (patch) | |
tree | 473503ed33bdfc07f3253b27341b8c675c19d68a | |
parent | d4a381ae00f97c00e25cdc2d9440c1d21566ba90 (diff) | |
download | alarm-manager-80b42d375a6d70833b1e068cebafe80ca9a859f6.tar.gz alarm-manager-80b42d375a6d70833b1e068cebafe80ca9a859f6.tar.bz2 alarm-manager-80b42d375a6d70833b1e068cebafe80ca9a859f6.zip |
Improve logs
Change-Id: I17bc94488338ce9dfa8c45b284a477ce007c112f
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
-rw-r--r-- | alarm-manager.c | 215 | ||||
-rwxr-xr-x | packaging/alarm-manager.spec | 4 |
2 files changed, 145 insertions, 74 deletions
diff --git a/alarm-manager.c b/alarm-manager.c index 3ea3db5..ae5b0f9 100644 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -97,10 +97,11 @@ static int gfd = -1; #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG #define ALARMMGR_LOG_BUFFER_SIZE 10000 -#define ALARMMGR_LOG_BUFFER_STRING_SIZE 200 +#define ALARMMGR_LOG_BUFFER_STRING_SIZE 400 #define ALARMMGR_LOG_TAG_SIZE 20 -#define ALARMMGR_LOG_MESSAGE_SIZE 120 -#define ALARMMGR_LOG_FILE_PATH "/run/alarmmgr_log/alarmmgr.log" +#define ALARMMGR_LOG_MESSAGE_SIZE 330 +#define ALARMMGR_LOG_DIR_PATH "/var/log/appfw/alarmmgr_log/" +#define ALARMMGR_LOG_FILE_PATH "/var/log/appfw/alarmmgr_log/alarmmgr.log" static int log_index = 0; static int log_fd = 0; #endif @@ -176,6 +177,7 @@ 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_alarm_info_log(const char *tag, __alarm_info_t *info); #endif int __display_lock_state(char *state, char *flag, unsigned int timeout); @@ -443,12 +445,13 @@ int __set_time(time_t _time) } #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG else - strncpy(log_tag, "SET RTC", sizeof(log_tag) - 1); + strncpy(log_tag, "SET RTC START", 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); + snprintf(log_message, sizeof(log_message), "RTC & OS =%ld, %s", + _time, timebuf); } __save_module_log(log_tag, log_message); @@ -810,9 +813,9 @@ static bool __alarm_update_due_time_of_all_items_in_list(time_t new_time, double if ((entry->due_time + diff_time - new_time) > (entry->due_time - entry->alarm_info.reserved_info)) { LOGE("[ RTC reset]: new time %s %ld, diff %f, id %d duetime %s %ld %ld", - ctime(&new_time), new_time, diff_time, entry->alarm_id, - ctime(&entry->due_time), entry->due_time, - entry->alarm_info.reserved_info); + ctime(&new_time), (long)new_time, diff_time, entry->alarm_id, + ctime(&entry->due_time), (long)entry->due_time, + (long)entry->alarm_info.reserved_info); continue; } @@ -827,9 +830,9 @@ static bool __alarm_update_due_time_of_all_items_in_list(time_t new_time, double entry->due_time = new_time + ((entry->due_time - new_time) % alarm_info->mode.u_interval.interval); LOGE("[ RTC reset]: new time %s %ld, diff %f, id %d duetime %s %ld %ld", - ctime(&new_time), new_time, diff_time, entry->alarm_id, - ctime(&entry->due_time), entry->due_time, - alarm_info->mode.u_interval.interval); + ctime(&new_time), (long)new_time, diff_time, entry->alarm_id, + ctime(&entry->due_time), (long)entry->due_time, + (long)alarm_info->mode.u_interval.interval); } } @@ -1015,6 +1018,10 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id due_time = _alarm_next_duetime(__alarm_info); __alarm_add_to_list(__alarm_info); +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + __save_alarm_info_log("CREATE SVC", __alarm_info); +#endif + if (due_time == 0) { ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: " "due_time is 0, alarm(%d) \n", *alarm_id); @@ -1135,6 +1142,10 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t due_time = _alarm_next_duetime(__alarm_info); __alarm_add_to_list(__alarm_info); +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + __save_alarm_info_log("CREATE", __alarm_info); +#endif + if (due_time == 0) { ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id); return true; @@ -1300,6 +1311,10 @@ static bool __alarm_create_noti(alarm_info_t *alarm_info, alarm_id_t *alarm_id, due_time = _alarm_next_duetime(__alarm_info); __alarm_add_to_list(__alarm_info); +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + __save_alarm_info_log("CREATE NOTI", __alarm_info); +#endif + if (due_time == 0) { ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id); return true; @@ -1364,6 +1379,10 @@ static bool __alarm_update(uid_t uid, int pid, alarm_id_t alarm_id, result = _remove_from_scheduled_alarm_list(uid, alarm_id); +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + __save_alarm_info_log("UPDATE", __alarm_info); +#endif + if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) { /*there is no scheduled alarm */ _alarm_disable_timer(alarm_context); @@ -1922,9 +1941,6 @@ static void __alarm_expired() bundle *b = NULL; char *appid = NULL; uid_t target_uid; -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; -#endif ALARM_MGR_LOG_PRINT("[alarm-server]: Enter"); @@ -2140,16 +2156,21 @@ static void __alarm_expired() } ALARM_MGR_LOG_PRINT("alarm_id[%d] is expired.", alarm_id); + SECURE_LOGW("alarm_expired : from [uid : %d, pid : %d, pkgid : %s, " + "unique_name : %s]", __alarm_info->uid,__alarm_info->pid, + __alarm_info->caller_pkgid, __alarm_info->app_unique_name); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d, duetime: %ld", alarm_id, app_pid, __alarm_info->due_time); - __save_module_log("EXPIRED", log_message); + __save_alarm_info_log("EXPIRED", __alarm_info); #endif - - if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) + if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) { __alarm_remove_from_list(__alarm_info->uid, alarm_id, NULL); - else + } else { _alarm_next_duetime(__alarm_info); +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + __save_alarm_info_log("DUETIME", __alarm_info); +#endif + } } done: @@ -2250,6 +2271,10 @@ static void __on_system_time_external_changed(keynode_t *node, void *data) _alarm_schedule(); __rtc_set(); +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + __save_module_log("SET RTC END", "requested by vconf"); +#endif + return; } @@ -2537,6 +2562,17 @@ static void __initialize_module_log(void) { char buf[1024]; + if (access(ALARMMGR_LOG_DIR_PATH, F_OK)) { + ALARM_MGR_EXCEPTION_PRINT("Not exist(%s)", ALARMMGR_LOG_DIR_PATH); + + if (mkdir(ALARMMGR_LOG_DIR_PATH, (S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP))) { + ALARM_MGR_EXCEPTION_PRINT("Failed to create directory(%s). errno(%d)", + ALARMMGR_LOG_DIR_PATH, errno); + return; + } + } + log_fd = open(ALARMMGR_LOG_FILE_PATH, O_CREAT | O_WRONLY, 0644); if (log_fd == -1) { ALARM_MGR_EXCEPTION_PRINT("Opening the file for alarmmgr log is failed. err: %s", strerror_r(errno, buf, sizeof(buf))); @@ -2559,6 +2595,7 @@ static bool __save_module_log(const char *tag, const char *message) char buffer[ALARMMGR_LOG_BUFFER_STRING_SIZE] = {0,}; time_t now; char buf[1024]; + char *time_str; if (log_fd == -1) { ALARM_MGR_EXCEPTION_PRINT("The file is not ready."); @@ -2571,7 +2608,13 @@ static bool __save_module_log(const char *tag, const char *message) lseek(log_fd, 0, SEEK_SET); time(&now); - snprintf(buffer, ALARMMGR_LOG_BUFFER_STRING_SIZE, "[%-6d] %-20s %-120s %d-%s", log_index, tag, message, (int)now, ctime(&now)); + time_str = ctime(&now); + if (time_str) + time_str[strlen(time_str) - 1] = '\0'; /* to avoid new line */ + + snprintf(buffer, ALARMMGR_LOG_BUFFER_STRING_SIZE, "[%-6d]%s\t%s\t : %ld %s", log_index, tag, message, now, time_str); + + SECURE_LOGW("%s", buffer); int ret = write(log_fd, buffer, strlen(buffer)); if (ret < 0) { @@ -2584,6 +2627,34 @@ static bool __save_module_log(const char *tag, const char *message) return true; } + +static void __save_alarm_info_log(const char *tag, __alarm_info_t *info) +{ + char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; + char *due_time_str = ctime(&(info->due_time)); + if (due_time_str) + due_time_str[strlen(due_time_str) - 1] = '\0'; /* to avoid new line */ + + char *timebuf = strdup(ctime(&info->due_time)); + if (timebuf) + timebuf[strlen(timebuf) - 1] = '\0'; /* to avoid new line */ + + snprintf(log_message, sizeof(log_message), + "alarmID: %d, uid: %d, caller : %s(%d) -> callee : %s, " + "dst_name %s, dst_mod %s, " + "type 0x%x, mode %d, " + "interval:%ld, duetime: %ld %s", + info->alarm_id, info->uid, info->app_unique_name, info->pid, info->callee_pkgid, + info->dst_service_name, info->dst_service_name_mod, + info->alarm_info.alarm_type, info->alarm_info.mode.repeat, + info->alarm_info.mode.u_interval.interval, info->due_time, timebuf); + + if (timebuf) + free(timebuf); + + __save_module_log(tag, log_message); +} + #endif /* _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG */ int __display_lock_state(char *state, char *flag, unsigned int timeout) @@ -2964,7 +3035,11 @@ gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation double diff_time = 0.0; struct timeval cur_time = {0,}; int return_code = ALARMMGR_RESULT_SUCCESS; - +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + guint pid; + char sender_id[MAX_APP_ID]; + char log_message[ALARMMGR_LOG_MESSAGE_SIZE]; +#endif _alarm_disable_timer(alarm_context); /* Disable the timer to reschedule the alarm before the time is changed. */ tzset(); @@ -2980,10 +3055,18 @@ gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation __set_time(time_sec); /* Change both OS time and RTC */ 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); + cur_time.tv_sec, time_sec, ctime((const time_t *)&time_sec), diff_time); __reschedule_alarms_with_newtime(cur_time.tv_sec, time_sec, diff_time); g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); + +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + pid = __get_caller_pid(g_dbus_method_invocation_get_sender(invoc)); + __get_cached_unique_name(pid, sender_id, MAX_APP_ID, NULL, 5001); + snprintf(log_message, sizeof(log_message), "requested by %s (pid %d)", sender_id, pid); + __save_module_log("SET RTC END", log_message); +#endif + return true; } @@ -2996,6 +3079,11 @@ gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, struct timespec sleep_time = {0,}; guint real_newtime = 0; accrue_msec = 0; /* reset accrued msec */ +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + guint pid; + char sender_id[MAX_APP_ID]; + char log_message[ALARMMGR_LOG_MESSAGE_SIZE]; +#endif _alarm_disable_timer(alarm_context); /* Disable the timer to reschedule the alarm before the time is changed. */ @@ -3037,6 +3125,14 @@ gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, ALARM_MGR_LOG_PRINT("Requested(%d.%09d) Delay(%ld.%09ld) Sleep(%09ld)", req_sec, req_nsec, delay.tv_sec, delay.tv_nsec, sleep_time.tv_nsec); __reschedule_alarms_with_newtime(cur_time.tv_sec, real_newtime, diff_time); g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ALARMMGR_RESULT_SUCCESS)); + +#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG + pid = __get_caller_pid(g_dbus_method_invocation_get_sender(invoc)); + __get_cached_unique_name(pid, sender_id, MAX_APP_ID, NULL, 5001); + snprintf(log_message, sizeof(log_message), "requested by %s (pid %d)", sender_id, pid); + __save_module_log("SET RTC END", log_message); +#endif + return true; } @@ -3213,21 +3309,14 @@ gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInv ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); -#endif - } else { -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); + snprintf(log_message, sizeof(log_message), + "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", + alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); + __save_module_log(log_tag, log_message); #endif } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); - __save_module_log(log_tag, log_message); -#endif - return true; } @@ -3303,21 +3392,15 @@ gboolean alarm_manager_alarm_create_noti(AlarmManager *pObject, GDBusMethodInvoc ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); -#endif - } else { -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); + snprintf(log_message, sizeof(log_message), + "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", + alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); + __save_module_log(log_tag, log_message); #endif } g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); - __save_module_log(log_tag, log_message); -#endif - return true; } @@ -3382,21 +3465,15 @@ gboolean alarm_manager_alarm_create(AlarmManager *obj, GDBusMethodInvocation *in ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); -#endif - } else { -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); + snprintf(log_message, sizeof(log_message), + "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", + alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); + __save_module_log(log_tag, log_message); #endif } g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); - __save_module_log(log_tag, log_message); -#endif - return true; } @@ -3474,22 +3551,17 @@ gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvoc ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); -#endif - } else { -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); + snprintf(log_message, sizeof(log_message), + "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", + alarm_id, uid, pid, alarm_info.start.year, alarm_info.start.month, + alarm_info.start.day, alarm_info.start.hour, + alarm_info.start.min, alarm_info.start.sec); + __save_module_log(log_tag, log_message); #endif } g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, alarm_info.start.year, alarm_info.start.month, - alarm_info.start.day, alarm_info.start.hour, - alarm_info.start.min, alarm_info.start.sec); - __save_module_log(log_tag, log_message); -#endif return true; } @@ -3677,21 +3749,16 @@ gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *i ALARM_MGR_EXCEPTION_PRINT("Unable to update the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: UPDATE", sizeof(log_tag) - 1); -#endif - } else { -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - strncpy(log_tag, "UPDATE", sizeof(log_tag) - 1); + snprintf(log_message, sizeof(log_message), + "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", + alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); + __save_module_log(log_tag, log_message); + #endif } g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); -#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG - snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); - __save_module_log(log_tag, log_message); -#endif - return true; } diff --git a/packaging/alarm-manager.spec b/packaging/alarm-manager.spec index 4b09720..09a058e 100755 --- a/packaging/alarm-manager.spec +++ b/packaging/alarm-manager.spec @@ -37,6 +37,8 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) BuildRequires: pkgconfig(cynara-creds-gdbus) +%define logdir /var/log/appfw/alarmmgr_log + %description Alarm Server and devel libraries @@ -134,6 +136,7 @@ mkdir -p %{buildroot}%{_tmpfilesdir} install -m 0644 %SOURCE4 %{buildroot}%{_tmpfilesdir}/alarm-manager.conf mkdir -p %{buildroot}%{_libdir}/udev/rules.d install -m 0644 %SOURCE5 %{buildroot}%{_libdir}/udev/rules.d +mkdir -p %{buildroot}%{logdir} %post -p /sbin/ldconfig @@ -172,6 +175,7 @@ fi %{_libdir}/udev/rules.d/99-rtc.rules %if 0%{?appfw_feature_alarm_manager_module_log} %attr(0755,root,root) %{TZ_SYS_ETC}/dump.d/module.d/alarmmgr_log_dump.sh +%attr(0755,app_fw,app_fw) %{logdir} %endif %files -n libalarm |