Fix StepKillApps
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 15 Jan 2019 23:04:56 +0000 (08:04 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 16 Jan 2019 04:57:19 +0000 (13:57 +0900)
This patch adds to check the elapsed time. After sending the terminate request,
we have to wait at least 5 seconds. According to Tizen policy,
the running application should be terminated within 5 seconds.
If the elapsed time exceeds 5 seconds, we send the kill request
to Application Manager to terminate the application forcedly.

Change-Id: Ic504f0899cfa55a13ff1eb2b8f6eee87ae9ec1ab
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/common/step/pkgmgr/step_kill_apps.cc

index b8a531a..bd38746 100644 (file)
@@ -8,6 +8,7 @@
 #include <systemd/sd-login.h>
 #include <aul.h>
 
+#include <chrono>
 #include <string>
 
 #include "common/utils/glist_range.h"
@@ -26,13 +27,36 @@ bool CheckAndKill(const std::string& appid, uid_t uid) {
     return true;
   }
 
-  ret = aul_terminate_pid_sync_without_restart_for_uid(pid, uid);
-  if (ret != AUL_R_OK) {
-    LOG(ERROR) << "Failed to kill app[" << appid << "] for uid [" << uid << "]";
-    return false;
-  }
+  int retry = 3;
+  auto start = std::chrono::steady_clock::now();
+  do {
+    ret = aul_terminate_pid_sync_without_restart_for_uid(pid, uid);
+    if (ret == AUL_R_OK) {
+      return true;
+    } else {
+      LOG(ERROR) << "Failed to terminate app[" << appid
+                 << "] for uid [" << uid << "]";
+      auto end = std::chrono::steady_clock::now();
+      auto elapsed_time =
+          std::chrono::duration_cast<std::chrono::milliseconds>(
+              end - start).count();
+      if (elapsed_time >= 5000)
+        break;
+    }
+  } while (retry--);
+
+  /*
+   * The elapsed time exceeded 5 seconds.
+   * According to Tizen policy, the running application should be terminated
+   * within 5 seconds. To terminate the running application forcedly,
+   * we send the kill request to Application Manager.
+   */
+  ret = aul_kill_pid(pid);
+  if (ret == AUL_R_OK)
+    return true;
 
-  return true;
+  LOG(ERROR) << "Failed to kill app[" << appid << "] for uid [" << uid << "]";
+  return false;
 }
 
 bool KillApp(const std::string& appid, const uid_t uid) {