Store global uid as static variable 73/260873/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 6 Jul 2021 06:56:39 +0000 (15:56 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 22 Jul 2021 08:59:46 +0000 (08:59 +0000)
Change-Id: I7b7fdaf6072f2b9af82aa3f491de50b6fc8a92a6
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/server/database/abstract_db_handler.cc
src/server/database/db_handle_provider.cc

index e53cfcb..de4f11e 100644 (file)
@@ -137,11 +137,17 @@ int __open_create_db(uid_t uid, const char* path,
   return ret;
 }
 
+static uid_t globaluser_uid = -1;
+
 uid_t ConvertUID(uid_t uid) {
-  if (uid < REGULAR_USER)
-    return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-  else
+  if (uid < REGULAR_USER) {
+    if (globaluser_uid == (uid_t)-1)
+      globaluser_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+    return globaluser_uid;
+  } else {
     return uid;
+  }
 }
 
 }  // namespace
index 1210b4a..d51a8e9 100644 (file)
@@ -39,13 +39,18 @@ namespace {
 
 constexpr uid_t REGULAR_USER = 5000;
 
+uid_t globaluser_uid = -1;
+
 uid_t GetGlobalUID() {
-  return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+  if (globaluser_uid == (uid_t)-1)
+    globaluser_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+  return globaluser_uid;
 }
 
 uid_t ConvertUID(uid_t uid) {
   if (uid < REGULAR_USER)
-    return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+    return GetGlobalUID();
   else
     return uid;
 }