"file:certdb?mode=memory&cache=shared";
std::string DBHandleProvider::cert_file_db_path_;
std::unordered_set<pid_t> 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) {
std::vector<std::string> DBHandleProvider::GetParserDBPath(pid_t pid) {
std::unique_lock<std::recursive_mutex> u(lock_);
+ std::unique_lock<std::recursive_mutex> gu(global_lock_);
std::vector<std::string> db_path_list;
if (is_memory_ != is_memory_global_)
SetMemoryMode(pid, is_memory_global_);
std::string DBHandleProvider::GetCertDBPath(pid_t pid) {
std::unique_lock<std::recursive_mutex> u(lock_);
+ std::unique_lock<std::recursive_mutex> gu(global_lock_);
if (is_memory_ != is_memory_global_)
SetMemoryMode(pid, is_memory_global_);
}
void DBHandleProvider::SetMemoryMode(pid_t pid, bool flag) {
- std::unique_lock<std::recursive_mutex>(lock_);
- std::unique_lock<std::recursive_mutex>(global_lock_);
+ std::unique_lock<std::recursive_mutex> u(lock_);
+ std::unique_lock<std::recursive_mutex> gu(global_lock_);
if (flag == is_memory_global_ && flag == is_memory_)
return;
static std::string cert_memory_db_path_;
static std::string cert_file_db_path_;
static std::unordered_set<pid_t> pid_list_;
- static std::mutex global_lock_;
+ static std::recursive_mutex global_lock_;
uid_t uid_;
+ bool is_memory_;
std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
std::string parser_memory_db_path_;
std::string parser_file_db_path_;
- bool is_memory_;
std::recursive_mutex lock_;
};
}
g_list_free(list);
- break;
}
return ret;
} else {
vconf_ignore_key_changed(VCONFKEY_LANGSET, OnLanguageChange);
}
+int Runner::FdErrorHandler(int fd, GIOCondition cond, void* user_data) {
+ auto runner = static_cast<Runner*>(user_data);
+ if (static_cast<int>(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<int>(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<Runner*>(user_data);
int client_fd = runner->server_->Accept();
return G_SOURCE_CONTINUE;
}
+ auto condition = static_cast<GIOCondition>(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;
}
#define SERVER_RUNNER_HH_
#include <gio/gio.h>
+#include <glib-unix.h>
#include <vconf.h>
#include <memory>
+#include <unordered_map>
#include "server_socket.hh"
#include "worker_thread.hh"
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<int, int> sid_map_;
std::unique_ptr<pkgmgr_common::socket::ServerSocket> server_;
std::unique_ptr<WorkerThread> thread_pool_;
};