diff options
author | Jiwoong Im <jiwoong.im@samsung.com> | 2015-06-26 13:25:28 +0900 |
---|---|---|
committer | Sangyoon Jang <s89.jang@samsung.com> | 2015-07-01 17:35:32 -0700 |
commit | 89cb9e2625739ac9571d4089a684a247a968de57 (patch) | |
tree | 2304ccaa001f38c203499ce42b4fa08fd41c71d0 | |
parent | 4127841d528cb979c21b03bb01d366330b319dd4 (diff) | |
download | alarm-manager-submit/tizen/20150702.004900.tar.gz alarm-manager-submit/tizen/20150702.004900.tar.bz2 alarm-manager-submit/tizen/20150702.004900.zip |
get caller unique name when caller is not application.submit/tizen/20150702.004900accepted/tizen/wearable/20150702.105020accepted/tizen/tv/20150702.105006accepted/tizen/mobile/20150702.104951
Change-Id: I840fd79801d32fbeb7ae4ab582d6f274eae71761
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
-rw-r--r-- | alarm-manager.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/alarm-manager.c b/alarm-manager.c index 68848f2..8530b99 100644 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -1563,25 +1563,48 @@ bool __get_caller_unique_name(int pid, char *unique_name) char caller_appid[256] = {0,}; char caller_cmdline[512] = {0,}; - if (unique_name == NULL) - { + if (unique_name == NULL) { ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL."); return false; } - if (aul_app_get_appid_bypid(pid, caller_appid, sizeof(caller_appid)) == AUL_R_OK) - { - // When a caller is an application, the unique name is appID. + if (aul_app_get_appid_bypid(pid, caller_appid, + sizeof(caller_appid)) == AUL_R_OK) { + /* When a caller is an application, the unique name is appID. */ strncpy(unique_name, caller_appid, strlen(caller_appid)); -/* } - else if (aul_app_get_cmdline_bypid(pid, caller_cmdline, sizeof(caller_cmdline)) == AUL_R_OK) - { - strncpy(unique_name, caller_cmdline, strlen(caller_cmdline)); - ALARM_MGR_LOG_PRINT("unique_name is caller_cmdline : %s.", unique_name); - */ } else { - ALARM_MGR_EXCEPTION_PRINT("Failed to get caller_cmdline"); - return false; + /* Otherwise, the unique name is /proc/pid/cmdline. */ + char proc_file[512] = {0,}; + char process_name[512] = {0,}; + int fd = 0; + int i = 0; + + snprintf(proc_file, 512, "/proc/%d/cmdline", pid); + + fd = open(proc_file, O_RDONLY); + if (fd < 0) { + SECURE_LOGE("Caution!! pid(%d) seems to be killed.", + pid, proc_file); + return false; + } + else { + if (read(fd, process_name, 512) <= 0) + { + ALARM_MGR_EXCEPTION_PRINT("Unable to get the process name."); + close(fd); + return false; + } + close(fd); + + while (process_name[i] != '\0') { + if (process_name[i] == ' ') { + process_name[i] = '\0'; + break; + } + ++i; + } + strncpy(unique_name, process_name, strlen(process_name)); + } } SECURE_LOGD("unique_name= %s", unique_name); |