From: Changgyu Choi Date: Thu, 18 Mar 2021 08:43:02 +0000 (+0900) Subject: Add to check to crash process X-Git-Tag: submit/tizen/20210323.054210^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F38%2F255438%2F8;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Add to check to crash process 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 --- diff --git a/src/common/database/db_handle_provider.cc b/src/common/database/db_handle_provider.cc index 4ceb9d5..46b8c95 100644 --- a/src/common/database/db_handle_provider.cc +++ b/src/common/database/db_handle_provider.cc @@ -14,15 +14,16 @@ * limitations under the License. */ -#include "db_handle_provider.hh" - +#include #include #include #include +#include #include +#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 u(lock_); + if (pid_list_.empty()) + return false; + bool ret = true; + LOGD("Check process count : %d", pid_list_.size()); + std::vector 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> DBHandleProvider::GetParserDBPath( pid_t pid, bool write) { std::unique_lock u(lock_); diff --git a/src/common/database/db_handle_provider.hh b/src/common/database/db_handle_provider.hh index a42bd04..c7ad5a6 100644 --- a/src/common/database/db_handle_provider.hh +++ b/src/common/database/db_handle_provider.hh @@ -40,6 +40,7 @@ class EXPORT_API DBHandleProvider { public: ~DBHandleProvider() = default; static DBHandleProvider& GetInst(uid_t uid); + static bool IsCrashedWriteRequest(); std::vector> GetParserDBPath(int pid, bool write); std::string GetCertDBPath(int pid, bool write); void SetMemoryMode(int pid, bool flag); diff --git a/src/server/worker_thread.cc b/src/server/worker_thread.cc index c150088..24cb4a6 100644 --- a/src/server/worker_thread.cc +++ b/src/server/worker_thread.cc @@ -14,10 +14,12 @@ * limitations under the License. */ -#include "worker_thread.hh" #include #include +#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; }