Change pid related bahavior
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 9 Mar 2021 02:42:27 +0000 (11:42 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 9 Mar 2021 02:42:27 +0000 (11:42 +0900)
- Set pid into request handler before execut it.
- Change pid_list_ into static and add setter codes.

Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/database/db_handle_provider.cc
src/common/database/db_handle_provider.hh
src/server/worker_thread.cc

index 5ecb086..50cc4ca 100644 (file)
@@ -56,6 +56,7 @@ namespace pkgmgr_common {
 std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>>
     DBHandleProvider::provider_;
 bool DBHandleProvider::is_memory_ = false;
+std::vector<pid_t> DBHandleProvider::pid_list_;
 
 DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
     global_parser_memory_db_handle_(nullptr, sqlite3_close_v2),
@@ -180,6 +181,11 @@ void DBHandleProvider::SetMemoryMode(pid_t pid, bool flag) {
         cert_memory_db_path_);
     if (cert_db != nullptr)
       cert_memory_db_handle_.reset(cert_db);
+    std::vector<pid_t>::iterator it =
+        std::find(pid_list_.begin(), pid_list_.end(), pid);
+
+    if (it == pid_list_.end())
+      pid_list_.emplace_back(pid);
   } else {
     parser_memory_db_handle_.reset(nullptr);
     cert_memory_db_handle_.reset(nullptr);
index cf74af0..6968bef 100644 (file)
@@ -61,7 +61,7 @@ class EXPORT_API DBHandleProvider {
   std::string cert_memory_db_path_;
   std::string cert_file_db_path_;
   static bool is_memory_;
-  std::vector<pid_t> pid_list_;
+  static std::vector<pid_t> pid_list_;
   std::mutex lock_;
 };
 
index 587f75d..42ac368 100644 (file)
@@ -106,6 +106,7 @@ void WorkerThread::Run() {
     }
 
     try {
+      handler[type]->SetPID(req->GetSenderPID());
       if (!handler[type]->HandleRequest(req->GetData(), req->GetSize(),
                                         locale_.GetObject()))
         LOGE("Failed to handle request");