Add to check to crash process 38/255438/8 submit/tizen/20210323.054210
authorChanggyu Choi <changyu.choi@samsung.com>
Thu, 18 Mar 2021 08:43:02 +0000 (17:43 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 22 Mar 2021 05:07:35 +0000 (05:07 +0000)
When TrimMemory() is called , it checks if there is a dead process
among the processes that requested the write.

Change-Id: I95732a8b178e2c0abb4f4e449151f861a7b59cb8
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/common/database/db_handle_provider.cc
src/common/database/db_handle_provider.hh
src/server/worker_thread.cc

index 4ceb9d5..46b8c95 100644 (file)
  * limitations under the License.
  */
 
-#include "db_handle_provider.hh"
-
+#include <fcntl.h>
 #include <sys/types.h>
 
 #include <tzplatform_config.h>
 
 #include <algorithm>
+#include <string>
 #include <vector>
 
+#include "db_handle_provider.hh"
 #include "pkgmgrinfo_debug.h"
 #include "pkgmgr-info.h"
 
@@ -100,6 +101,32 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
   return *prov;
 }
 
+bool DBHandleProvider::IsCrashedWriteRequest() {
+  std::unique_lock<std::recursive_mutex> u(lock_);
+  if (pid_list_.empty())
+    return false;
+  bool ret = true;
+  LOGD("Check process count : %d", pid_list_.size());
+  std::vector<pid_t> remove_pids;
+  for (pid_t pid : pid_list_) {
+    std::string status_path = "/proc/" + std::to_string(pid) + "/status";
+
+    int fd = open(status_path.c_str(), O_RDONLY);
+    if (fd < 0) {
+      LOGE("Process is crashed (%d)", pid);
+      remove_pids.push_back(pid);
+    } else {
+      ret = false;
+      close(fd);
+    }
+  }
+
+  for (pid_t pid : remove_pids)
+    pid_list_.erase(pid);
+
+  return ret;
+}
+
 std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(
     pid_t pid, bool write) {
   std::unique_lock<std::recursive_mutex> u(lock_);
index a42bd04..c7ad5a6 100644 (file)
@@ -40,6 +40,7 @@ class EXPORT_API DBHandleProvider {
  public:
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
+  static bool IsCrashedWriteRequest();
   std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid, bool write);
   std::string GetCertDBPath(int pid, bool write);
   void SetMemoryMode(int pid, bool flag);
index c150088..24cb4a6 100644 (file)
  * limitations under the License.
  */
 
-#include "worker_thread.hh"
 #include <sqlite3.h>
 #include <malloc.h>
 
+#include "worker_thread.hh"
+#include "db_handle_provider.hh"
+
 #include "pkgmgrinfo_debug.h"
 #include "get_appinfo_request_handler.hh"
 #include "get_cert_request_handler.hh"
@@ -162,6 +164,10 @@ gboolean WorkerThread::TrimMemory(void* data) {
   malloc_trim(0);
   *timer = 0;
 
+  if (pkgmgr_common::DBHandleProvider::IsCrashedWriteRequest())
+    pkgmgr_common::DBHandleProvider::
+        GetInst(getuid()).SetMemoryMode(getpid(), false);
+
   return false;
 }