From: Sangyoon Jang Date: Wed, 12 Oct 2016 04:52:00 +0000 (+0900) Subject: Kill app using aul api instead of proc filesystem X-Git-Tag: accepted/tizen/common/20161012.154713~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4257da53934d4d6e1f0780d81d5c0bb748698692;p=platform%2Fcore%2Fappfw%2Fpkgmgr-server.git Kill app using aul api instead of proc filesystem Change-Id: Ic48077821e5c81b378510deba30ecf0741b5e310 Signed-off-by: Sangyoon Jang --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3abb01a..3c76497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ SET(SRCS src/signal.c ) -SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd) +SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul) IF(TIZEN_FEATURE_CSR) SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index dbb360f..ef78063 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(iniparser) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 764894a..2abd40f 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include +#include #include #include #include @@ -291,44 +291,6 @@ gboolean exit_server(void *data) return TRUE; } -static int __pkgcmd_read_proc(const char *path, char *buf, int size) -{ - int fd; - int ret; - if (buf == NULL || path == NULL) - return -1; - fd = open(path, O_RDONLY); - if (fd < 0) - return -1; - ret = read(fd, buf, size - 1); - if (ret <= 0) { - close(fd); - return -1; - } else - buf[ret] = 0; - close(fd); - return ret; -} - -static int __pkgcmd_find_pid_by_cmdline(const char *dname, - const char *cmdline, const char *apppath) -{ - int pid = 0; - int pgid = 0; - - if (strcmp(cmdline, apppath) == 0) { - pid = atoi(dname); - pgid = getpgid(pid); - if (pgid < 0) { - ERR("getpgid failed, errno(%d)", errno); - pid = 0; - } - if (pid != pgid) - pid = 0; - } - return pid; -} - #ifdef TIZEN_FEATURE_CSR static int __check_csr(backend_info *ptr) { @@ -357,55 +319,6 @@ static int __check_csr(backend_info *ptr) } #endif -static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) -{ - DIR *dp; - struct dirent dentry, *result; - int pid; - int ret; - char buf[1024] = {'\0'}; - int pgid; - - dp = opendir("/proc"); - if (dp == NULL) - return -1; - - for (ret = readdir_r(dp, &dentry, &result); - ret == 0 && result != NULL; - ret = readdir_r(dp, &dentry, &result)) { - if (!isdigit(dentry.d_name[0])) - continue; - - snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry.d_name); - ret = __pkgcmd_read_proc(buf, buf, sizeof(buf)); - if (ret <= 0) - continue; - - pid = __pkgcmd_find_pid_by_cmdline(dentry.d_name, buf, apppath); - if (pid > 0) { - if (option == 0) { - closedir(dp); - return pid; - } - pgid = getpgid(pid); - if (pgid <= 1) { - closedir(dp); - ERR("getpgid failed, errno(%d)", errno); - return -1; - } - if (killpg(pgid, SIGKILL) < 0) { - closedir(dp); - ERR("killpg failed, errno(%d)", errno); - return -1; - } - closedir(dp); - return pid; - } - } - closedir(dp); - return 0; -} - static void __make_pid_info_file(char *req_key, int pid, uid_t uid) { FILE* file; @@ -450,31 +363,46 @@ static void __make_pid_info_file(char *req_key, int pid, uid_t uid) static int __kill_app(char *appid, uid_t uid) { - pkgmgrinfo_appinfo_h appinfo; - int ret = PMINFO_R_ERROR; - char *exec = NULL; + int ret; + int pid; + int is_running; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &appinfo); - if (ret != PMINFO_R_OK) - return PMINFO_R_ERROR; + is_running = aul_app_is_running_for_uid(appid, uid); + /* app is not running */ + if (!is_running) + return 0; - ret = pkgmgrinfo_appinfo_get_exec(appinfo, &exec); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_destroy_appinfo(appinfo); - return PMINFO_R_ERROR; + pid = aul_app_get_pid_for_uid(appid, uid); + if (pid == -1) + return -1; + + ret = aul_terminate_pid_for_uid(pid, uid); + if (ret != AUL_R_OK) { + ERR("failed to terminate app(%d)", appid); + return -1; } - ret = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - if (ret != PMINFO_R_OK) - DBG("failed to kill app[%s], exec[%s]", appid, exec); + return 0; +} - pkgmgrinfo_appinfo_destroy_appinfo(appinfo); - return ret; +static int __check_app(char *appid, uid_t uid) +{ + int pid; + int is_running; + + is_running = aul_app_is_running_for_uid(appid, uid); + if (!is_running) + return 0; + + pid = aul_app_get_pid_for_uid(appid, uid); + + return pid; } static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) { char *pkgid; + char *appid; char *exec; int ret; int pid = -1; @@ -489,16 +417,24 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) perror("Failed to get app exec path\n"); exit(1); } + ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); + if (ret) { + perror("Failed to get appid\n"); + exit(1); + } ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); if (ret) { perror("Failed to get pkgid\n"); exit(1); } - if (strcmp(pdata->cmd, "kill") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - else if (strcmp(pdata->cmd, "check") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0); + if (strcmp(pdata->cmd, "kill") == 0) { + pid = __check_app(appid, pdata->uid); + if (pid > 0) + ret = __kill_app(appid, pdata->uid); + } else if (strcmp(pdata->cmd, "check") == 0) { + pid = __check_app(appid, pdata->uid); + } __make_pid_info_file(pkgid, pid, pdata->uid); @@ -987,7 +923,7 @@ static int __process_disable_app(pm_dbus_msg *item) PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); ret = __kill_app(item->appid, item->uid); - if (ret != PMINFO_R_OK) { + if (ret != 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type);