From: Baptiste DURAND Date: Fri, 9 Jan 2015 09:01:53 +0000 (+0100) Subject: Fix App svc API Call X-Git-Tag: accepted/tizen/mobile/20150313.083949~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6dfcab4e7cf57a0cb96da6f2b6e95a8ed6b5ff19;p=platform%2Fcore%2Fappfw%2Falarm-manager.git Fix App svc API Call Retreive the uid from the owner of PID proc file. This permits to get the user that launched the app Signed-off-by: Baptiste DURAND Change-Id: I6863537bdb105618bcd7b9c648f2cad7e333f6c4 --- diff --git a/alarm-manager.c b/alarm-manager.c index 0e3b187..f6aef71 100644 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -682,7 +682,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id char caller_appid[512]; bundle_raw *b_data = NULL; int datalen = 0; - + uid_t uid; __alarm_info_t *__alarm_info = NULL; __alarm_info = malloc(sizeof(__alarm_info_t)); @@ -693,9 +693,19 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id failed internally. */ return false; } + uid = _proc_get_usr_bypid(pid); __alarm_info->pid = pid; __alarm_info->alarm_id = -1; - + if( uid < 0 ){ /* failure */ + ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " + "killed, so we failed to get proc owner and do not create " + "alarm_info\n", pid); + *error_code = -1; /*-1 means that system failed + internally.*/ + free(__alarm_info); + return false; + } else + __alarm_info->uid = uid; /* we should consider to check whether pid is running or Not */ @@ -840,6 +850,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, char app_name[256] = { 0 }; char *word = NULL; char *proc_name_ptr = NULL; + uid_t uid; __alarm_info_t *__alarm_info = NULL; @@ -851,9 +862,19 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, failed internally. */ return false; } + uid = _proc_get_usr_bypid(pid); __alarm_info->pid = pid; __alarm_info->alarm_id = -1; - + if( uid < 0 ){ /* failure */ + ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " + "killed, so we failed to get proc owner and do not create " + "alarm_info\n", pid); + *error_code = -1; /*-1 means that system failed + internally.*/ + free(__alarm_info); + return false; + } else + __alarm_info->uid = uid; /* we should consider to check whether pid is running or Not */ memset(process_name, '\0', 512); @@ -999,6 +1020,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id, { time_t current_time; time_t due_time; + uid_t uid; __alarm_info_t *__alarm_info = NULL; bool result = false; @@ -1011,10 +1033,21 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id, internally.*/ return false; } - + uid = _proc_get_usr_bypid(pid); __alarm_info->pid = pid; __alarm_info->alarm_id = alarm_id; + if( uid < 0 ){ /* failure */ + ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " + "killed, so we failed to get proc owner and do not create " + "alarm_info\n", pid); + *error_code = -1; /*-1 means that system failed + internally.*/ + free(__alarm_info); + return false; + } else + __alarm_info->uid = uid; + /* we should consider to check whether pid is running or Not */ @@ -1446,7 +1479,7 @@ static void __alarm_expired() } else { - if ( appsvc_run_service(b, 0, NULL, NULL) < 0) + if ( appsvc_run_service(b, 0, NULL, NULL, __alarm_info->uid) < 0) { ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n"); } @@ -2920,6 +2953,23 @@ static bool __check_false_alarm() } #endif + +uid_t _proc_get_usr_bypid(int pid) +{ + char buf[255]; + int ret; + uid_t uid; + struct stat dir_stats; + snprintf(buf, sizeof(buf), "/proc/%d", pid); + ret = stat(buf, &dir_stats); + if (ret < 0) + uid = (uid_t)-1; + else + uid = dir_stats.st_uid; + return uid; +} + + int main() { GMainLoop *mainloop = NULL; diff --git a/include/alarm-internal.h b/include/alarm-internal.h index 4f65c1f..62ae476 100644 --- a/include/alarm-internal.h +++ b/include/alarm-internal.h @@ -154,6 +154,7 @@ typedef struct { int alarm_id; int pid; + uid_t uid; GQuark quark_app_unique_name; /*the fullpath of application's pid is converted to quark value.*/ GQuark quark_app_service_name; /*dbus_service_name is converted to @@ -219,6 +220,7 @@ int _set_sys_time(time_t _time); int _set_time(time_t _time); time_t _alarm_time(time_t *tp); +uid_t _proc_get_usr_bypid(int pid); #ifdef _DEBUG_MODE_