Add lock while opening direct access library 50/278750/1
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 25 Jul 2022 11:44:58 +0000 (20:44 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 26 Jul 2022 00:17:42 +0000 (09:17 +0900)
Change-Id: I5db98c4aed67d9648afdab5ae49abc3b9457da09
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/client/pkginfo_client.cc

index 922bbf0..60aae7b 100644 (file)
@@ -10,6 +10,7 @@
 #include <parcel.hh>
 #include <vconf.h>
 
+#include <mutex>
 #include <string>
 
 #include "parcelable_factory.hh"
@@ -161,9 +162,11 @@ PkgInfoClient::GetResultParcel() {
 
 bool PkgInfoClient::RequestHandlerDirectAccess(
     const std::vector<uint8_t>& raw) {
+  static std::mutex lock;
   static void* handle = nullptr;
-  static void* (*dl_func)(int, const unsigned char*, int, const char *);
+  static void* (*dl_func)(int, const unsigned char*, int, const char*);
 
+  std::unique_lock<std::mutex> u(lock);
   if (handle == nullptr) {
     handle = dlopen(LIBPKGMGR_INFO, RTLD_GLOBAL | RTLD_LAZY);
     if (!handle) {
@@ -172,7 +175,7 @@ bool PkgInfoClient::RequestHandlerDirectAccess(
       return false;
     }
     dl_func = reinterpret_cast<void* (*)(
-        int, const unsigned char*, int, const char *)>(
+        int, const unsigned char*, int, const char*)>(
             dlsym(handle, DIRECT_ACCESS_FUNC));
     if (dl_func == nullptr) {
       LOG(ERROR) << "cannot find " << DIRECT_ACCESS_FUNC << " symbol in "
@@ -182,9 +185,10 @@ bool PkgInfoClient::RequestHandlerDirectAccess(
       return false;
     }
   }
+  u.unlock();
 
   result_parcel_.reset(
-      reinterpret_cast<pkgmgr_common::parcel::AbstractParcelable *>(
+      reinterpret_cast<pkgmgr_common::parcel::AbstractParcelable*>(
           dl_func(req_type_, &raw[0], raw.size(),
               pkgmgr_common::SystemLocale::GetInst(false).Get().c_str())));