From: 최창규/Tizen Platform Lab(SR)/Engineer/삼성전자 Date: Fri, 12 Mar 2021 04:12:03 +0000 (+0900) Subject: Fix implementation (#147) X-Git-Tag: submit/tizen/20210317.082331~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4daa7d3b3d9e3be59fc0f4af9b948e10625678bf;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Fix implementation (#147) * Fix implementation Changes: * Add global_lock_ into GetParserDBPath * Add error handling for socket fd. Signed-off-by: Changgyu Choi * Remove wrong break Signed-off-by: Changgyu Choi * Fix Wreorder warning --- diff --git a/src/common/database/db_handle_provider.cc b/src/common/database/db_handle_provider.cc index 28c7c0d..67bfc5a 100644 --- a/src/common/database/db_handle_provider.cc +++ b/src/common/database/db_handle_provider.cc @@ -63,7 +63,7 @@ std::string DBHandleProvider::cert_memory_db_path_ = "file:certdb?mode=memory&cache=shared"; std::string DBHandleProvider::cert_file_db_path_; std::unordered_set DBHandleProvider::pid_list_; -std::mutex DBHandleProvider::global_lock_; +std::recursive_mutex DBHandleProvider::global_lock_; DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid), is_memory_(false), parser_memory_db_handle_(nullptr, sqlite3_close_v2) { @@ -100,6 +100,7 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) { std::vector DBHandleProvider::GetParserDBPath(pid_t pid) { std::unique_lock u(lock_); + std::unique_lock gu(global_lock_); std::vector db_path_list; if (is_memory_ != is_memory_global_) SetMemoryMode(pid, is_memory_global_); @@ -126,6 +127,7 @@ std::vector DBHandleProvider::GetParserDBPath(pid_t pid) { std::string DBHandleProvider::GetCertDBPath(pid_t pid) { std::unique_lock u(lock_); + std::unique_lock gu(global_lock_); if (is_memory_ != is_memory_global_) SetMemoryMode(pid, is_memory_global_); @@ -171,8 +173,8 @@ sqlite3* DBHandleProvider::GetMemoryDBHandle(const std::string& filedb_path, } void DBHandleProvider::SetMemoryMode(pid_t pid, bool flag) { - std::unique_lock(lock_); - std::unique_lock(global_lock_); + std::unique_lock u(lock_); + std::unique_lock gu(global_lock_); if (flag == is_memory_global_ && flag == is_memory_) return; diff --git a/src/common/database/db_handle_provider.hh b/src/common/database/db_handle_provider.hh index 2e963a6..e315b64 100644 --- a/src/common/database/db_handle_provider.hh +++ b/src/common/database/db_handle_provider.hh @@ -61,13 +61,13 @@ class EXPORT_API DBHandleProvider { static std::string cert_memory_db_path_; static std::string cert_file_db_path_; static std::unordered_set pid_list_; - static std::mutex global_lock_; + static std::recursive_mutex global_lock_; uid_t uid_; + bool is_memory_; std::unique_ptr parser_memory_db_handle_; std::string parser_memory_db_path_; std::string parser_file_db_path_; - bool is_memory_; std::recursive_mutex lock_; }; diff --git a/src/common/database/query_handler.cc b/src/common/database/query_handler.cc index ba7dda4..20c1312 100644 --- a/src/common/database/query_handler.cc +++ b/src/common/database/query_handler.cc @@ -76,7 +76,6 @@ int QueryHandler::Execute() { } g_list_free(list); - break; } return ret; } else { diff --git a/src/server/runner.cc b/src/server/runner.cc index fb7afa0..878081a 100644 --- a/src/server/runner.cc +++ b/src/server/runner.cc @@ -46,6 +46,21 @@ Runner::~Runner() { vconf_ignore_key_changed(VCONFKEY_LANGSET, OnLanguageChange); } +int Runner::FdErrorHandler(int fd, GIOCondition cond, void* user_data) { + auto runner = static_cast(user_data); + if (static_cast(cond) & (G_IO_ERR | G_IO_HUP)) { + auto it = runner->sid_map_.find(fd); + if (it != runner->sid_map_.end()) { + LOGW("Socket disconnect. fd(%d) condition(%d)", fd, static_cast(cond)); + g_source_remove(it->second); + runner->sid_map_.erase(it); + } + close(fd); + } + + return G_SOURCE_CONTINUE; +} + int Runner::OnReceiveRequest(int fd, GIOCondition cond, void* user_data) { auto runner = static_cast(user_data); int client_fd = runner->server_->Accept(); @@ -54,6 +69,9 @@ int Runner::OnReceiveRequest(int fd, GIOCondition cond, void* user_data) { return G_SOURCE_CONTINUE; } + auto condition = static_cast(G_IO_ERR | G_IO_HUP); + int sid = g_unix_fd_add(client_fd, condition, FdErrorHandler, runner); + runner->sid_map_[client_fd] = sid; runner->QueueRequest(client_fd); return G_SOURCE_CONTINUE; } diff --git a/src/server/runner.hh b/src/server/runner.hh index 52ba888..eff5994 100644 --- a/src/server/runner.hh +++ b/src/server/runner.hh @@ -18,9 +18,11 @@ #define SERVER_RUNNER_HH_ #include +#include #include #include +#include #include "server_socket.hh" #include "worker_thread.hh" @@ -40,10 +42,12 @@ class EXPORT_API Runner { static int OnReceiveRequest(int fd, GIOCondition cond, void* user_data); static void OnLanguageChange(keynode_t* key, void* user_data); bool QueueRequest(int client_fd); + static int FdErrorHandler(int fd, GIOCondition cond, void* user_data); private: int sid_; int thread_num_; + std::unordered_map sid_map_; std::unique_ptr server_; std::unique_ptr thread_pool_; };