1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/pkgmgr/step_kill_apps.h"
8 #include <systemd/sd-login.h>
13 #include "common/utils/glist_range.h"
17 bool CheckAndKill(const std::string& appid, uid_t uid) {
18 int ret = aul_app_get_status_for_uid(appid.c_str(), uid);
22 int pid = aul_app_get_pid_for_uid(appid.c_str(), uid);
24 LOG(ERROR) << "Failed to get pid for appid[" << appid
25 << "] for uid [" << uid << "]";
29 ret = aul_terminate_pid_sync_without_restart_for_uid(pid, uid);
30 if (ret != AUL_R_OK) {
31 LOG(ERROR) << "Failed to kill app[" << appid << "] for uid [" << uid << "]";
38 bool KillApp(const std::string& appid, const uid_t uid) {
39 uid_t* uids = nullptr;
43 if (uid == 0 || uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
44 ret = sd_get_uids(&uids);
45 if (ret < 0 || (ret == 0 || uids == nullptr)) {
46 LOG(DEBUG) << "Failed to get uids [" << ret << "]";
50 for (i = 0; i < ret; i++) {
51 if (!CheckAndKill(appid, uids[i])) {
57 if (!CheckAndKill(appid, uid))
61 LOG(DEBUG) << "Application '" << appid << "' has been killed";
67 namespace common_installer {
70 Step::Status StepKillApps::process() {
71 manifest_x* old_manifest = context_->old_manifest_data.get() ?
72 context_->old_manifest_data.get() : context_->manifest_data.get();
73 for (application_x* app :
74 GListRange<application_x*>(old_manifest->application)) {
75 (void) KillApp(app->appid, context_->uid.get());
80 Step::Status StepKillApps::precheck() {
81 if (!context_->manifest_data.get() && !context_->old_manifest_data.get()) {
82 LOG(ERROR) << "manifest_data is empty";
89 } // namespace common_installer