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),
std::vector<std::string> DBHandleProvider::GetParserDBPath(pid_t pid) {
std::unique_lock<std::mutex> u(lock_);
std::vector<std::string> db_path_list;
- bool is_file_access = is_memory_;
- std::vector<pid_t>::iterator it = std::find(pid_list_.begin(),
- pid_list_.end(), pid);
- if (it == pid_list_.end())
- is_file_access = true;
+ bool tmp_is_memory = is_memory_;
- if (!is_file_access) {
+ if (tmp_is_memory) {
+ std::vector<pid_t>::iterator it = std::find(pid_list_.begin(),
+ pid_list_.end(), pid);
+ if (it != pid_list_.end())
+ tmp_is_memory = false;
+ }
+
+
+ if (tmp_is_memory) {
db_path_list.emplace_back(parser_memory_db_path_);
if (IsUserRequest(uid_))
db_path_list.emplace_back(global_parser_memory_db_path_);
std::string DBHandleProvider::GetCertDBPath(pid_t pid) {
std::unique_lock<std::mutex> u(lock_);
- bool is_file_access = is_memory_;
- std::vector<pid_t>::iterator it = std::find(pid_list_.begin(),
- pid_list_.end(), pid);
- if (it == pid_list_.end())
- is_file_access = true;
+ bool tmp_is_memory = is_memory_;
- if (!is_file_access)
+ if (tmp_is_memory) {
+ std::vector<pid_t>::iterator it = std::find(pid_list_.begin(),
+ pid_list_.end(), pid);
+ if (it != pid_list_.end())
+ tmp_is_memory = false;
+
+ if (tmp_is_memory)
return cert_memory_db_path_;
else
return cert_file_db_path_;
for (auto& conn : conn_list) {
ret = pkginfo_internal_filter_get_list(conn, filter_, uid_,
GetLocale().c_str(), &list);
- if (ret == PMINFO_R_ERROR) {
- g_hash_table_destroy(list);
+ if (ret == PMINFO_R_ERROR)
return ret;
- }
}
// TODO: possible memory leak?
struct ucred cred;
socklen_t len;
- r = getsockopt(fd_, SOCK_STREAM, SO_PEERCRED, &cred, &len);
+ r = getsockopt(fd_, SOL_SOCKET, SO_PEERCRED, &cred, &len);
+ if (r < 0) {
+ LOGE("getsockopt has failed, errno[%d]", errno);
+ return -1;
+ }
return cred.pid;
}