From 26e446e9298a68849285def7b9ffcba0cd120727 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 4 May 2016 16:31:41 +0900 Subject: [PATCH] Add APIs to close an application - These APIs wait util the target application is terminated successfully. - Add new internal APIs aul_terminate_pid_sync() aul_terminate_pid_sync_for_uid() Change-Id: I5c91924817b998bac636efe021c78b7bd06377a3 Signed-off-by: Hwankyu Jhun --- include/aul.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/aul_cmd.h | 1 + src/launch.c | 20 ++++++++++++++++++++ tool/aul_test.c | 20 ++++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/include/aul.h b/include/aul.h index acc70fc..215855a 100644 --- a/include/aul.h +++ b/include/aul.h @@ -776,6 +776,61 @@ int aul_terminate_pid_async(int pid); int aul_terminate_pid_async_for_uid(int pid, uid_t uid); /** + * @par Description: + * This API trigger to terminate application synchronously + * + * If the application is running, this API sends a terminate event to the application. \n + * And then, this API waits until the application is terminated successfully. \n + * If the app cannot receive the event, AUL kill forcely the application. \n + * @par Purpose: + * This API's purpose is to kill application + * @par Typical use case: + * In general, Application like Task Manager use this API. + * + * This API need to require root or platform level permisssion. \n + * + * @param[in] pid application's pid to be terminated + * @return 0 if success, negative value(<0) if fail + * @retval AUL_R_OK - success + * @retval AUL_R_EINVAL - invaild pid + * @retval AUL_R_ECOM - internal AUL IPC error + * @retval AUL_R_ERROR - general error + * @warning This API need to require root or platform level permisssion. \n + * @remark + * If you have not the permission, this API return AUL_R_ERROR. \n + * This API is only available in User Session. +*/ +int aul_terminate_pid_sync(int pid); + +/** + * @par Description: + * This API trigger to terminate application synchronously + * + * If the application is running, this API send a terminate event to the application. \n + * And then, this API waits until the application is terminated successfully. \n + * If the app cannot receive the event, AUL kill forcely the application. \n + * @par Purpose: + * This API's purpose is to kill application + * @par Typical use case: + * In general, Application like Task Manager use this API. + * + * This API need to require root or platform level permisssion. \n + * + * @param[in] pid application's pid to be terminated + * @param[in] uid User ID + * @return 0 if success, negative value(<0) if fail + * @retval AUL_R_OK - success + * @retval AUL_R_EINVAL - invaild pid + * @retval AUL_R_ECOM - internal AUL IPC error + * @retval AUL_R_ERROR - general error + * @warning This API need to require root or platform level permisssion. \n + * @remark + * If you have not the permission, this API return AUL_R_ERROR. \n + * This API is only available to System user. + */ +int aul_terminate_pid_sync_for_uid(int pid, uid_t uid); + +/** *@brief Running application's information structure retrieved by AUL */ typedef struct _aul_app_info { diff --git a/include/aul_cmd.h b/include/aul_cmd.h index b94de2b..1fb6fc0 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -91,6 +91,7 @@ enum app_cmd { APP_START_ASYNC, APP_SET_PROCESS_GROUP, APP_PREPARE_CANDIDATE_PROCESS, + APP_TERM_BY_PID_SYNC, APP_CMD_MAX }; diff --git a/src/launch.c b/src/launch.c index 9c2fdb8..01e5422 100644 --- a/src/launch.c +++ b/src/launch.c @@ -440,6 +440,7 @@ int aul_sock_handler(int fd) case APP_TERM_BY_PID: /* run in callee */ case APP_TERM_BY_PID_ASYNC: + case APP_TERM_BY_PID_SYNC: app_terminate(); break; @@ -1050,3 +1051,22 @@ API int aul_prepare_candidate_process(void) APP_PREPARE_CANDIDATE_PROCESS, dummy, 0, AUL_SOCK_NONE); } +API int aul_terminate_pid_sync(int pid) +{ + return aul_terminate_pid_sync_for_uid(pid, getuid()); +} + +API int aul_terminate_pid_sync_for_uid(int pid, uid_t uid) +{ + char pid_str[MAX_PID_STR_BUFSZ]; + int ret; + + if (pid <= 0) + return AUL_R_EINVAL; + + snprintf(pid_str, sizeof(pid_str), "%d", pid); + ret = app_request_to_launchpad_for_uid(APP_TERM_BY_PID_SYNC, pid_str, + NULL, uid); + return ret; +} + diff --git a/tool/aul_test.c b/tool/aul_test.c index fedf65e..42c52bb 100644 --- a/tool/aul_test.c +++ b/tool/aul_test.c @@ -602,6 +602,22 @@ static int pause_pid_test_for_uid() return aul_pause_pid_for_uid(apn_pid, atoi(gargv[3])); } +static int term_pid_sync_test() +{ + static int num = 0; + + printf("[aul_terminate_pid_sync %d test] %d \n", num++, apn_pid); + return aul_terminate_pid_sync(apn_pid); +} + +static int term_pid_sync_test_for_uid() +{ + static int num = 0; + + printf("[aul_terminate_pid_sync_for_uid %d test] %d \n", num++, apn_pid); + return aul_terminate_pid_sync_for_uid(apn_pid, atoi(gargv[3])); +} + /* static int set_pkg_func() { @@ -785,6 +801,10 @@ static test_func_t test_func[] = { "[usage] pasue_for_uid "}, {"pause_pid_for_uid", pause_pid_test_for_uid, "aul_pause_pid_for_uid test", "[usage] pause_pid_for_uid "}, + {"term_pid_sync", term_pid_sync_test, "aul_terminate_pid_sync test", + "[usage] term_pid_sync "}, + {"term_pid_sync_for_uid", term_pid_sync_test_for_uid, "aul_terminate_pid_sync_for_uid test", + "[usage] term_pid_sync_for_uid "}, }; int callfunc(char *testname) -- 2.7.4