Fix getting light user list 10/284110/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 10 Nov 2022 01:35:25 +0000 (10:35 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Thu, 10 Nov 2022 01:42:27 +0000 (10:42 +0900)
Get light user list by subsession directory name instead of using
sessiond API because of performance issue.

Change-Id: I16fdddae01045424cbf10fe87aa08facaa7680dd
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
CMakeLists.txt
packaging/app-installers.spec
src/common/CMakeLists.txt
src/common/utils/file_util.cc
src/common/utils/file_util.h
src/common/utils/user_util.cc

index d7ec4b5..7bb5529 100644 (file)
@@ -66,7 +66,6 @@ PKG_CHECK_MODULES(LIBSYSTEMD_DEPS REQUIRED libsystemd)
 PKG_CHECK_MODULES(TTRACE_DEPS REQUIRED ttrace)
 PKG_CHECK_MODULES(TRUST_ANCHOR_DEPS REQUIRED tanchor)
 PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
-PKG_CHECK_MODULES(LIBSESSIOND_DEPS REQUIRED libsessiond)
 
 FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem program_options iostreams)
 
index 95191ea..c1824bb 100644 (file)
@@ -40,7 +40,6 @@ BuildRequires:  pkgconfig(ttrace)
 BuildRequires:  pkgconfig(tanchor)
 BuildRequires:  pkgconfig(libsmack)
 BuildRequires:  pkgconfig(gmock)
-BuildRequires:  pkgconfig(libsessiond)
 
 Requires: ca-certificates-tizen
 Requires: libtzplatform-config
index 5e6d804..9858674 100644 (file)
@@ -55,7 +55,6 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_COMMON} PUBLIC
   TTRACE_DEPS
   TRUST_ANCHOR_DEPS
   Boost
-  LIBSESSIOND_DEPS
 )
 
 # Extra
@@ -90,4 +89,3 @@ INSTALL(DIRECTORY ./ DESTINATION ${INCLUDEDIR}/app-installers/common/
         FILES_MATCHING PATTERN "*.h")
 INSTALL(DIRECTORY ./installer/ DESTINATION ${INCLUDEDIR}/app-installers/common/
         FILES_MATCHING PATTERN "*.h")
-
index 76ce1de..8df33f4 100644 (file)
@@ -739,4 +739,19 @@ bf::path RelativePath(const bf::path& from,
   return result;
 }
 
+std::vector<std::string> GetDirectoryList(const boost::filesystem::path& cwd) {
+  if (!bf::exists(cwd))
+    return {};
+
+  std::vector<std::string> list;
+  for (bf::directory_iterator file(cwd); file != bf::directory_iterator();
+      ++file) {
+    if (!bf::is_directory(file->path()))
+      continue;
+    list.emplace_back(file->path().filename().string());
+  }
+
+  return list;
+}
+
 }  // namespace common_installer
index 45e943c..943f083 100644 (file)
@@ -98,6 +98,8 @@ bool IsSubDir(const boost::filesystem::path& path,
 boost::filesystem::path RelativePath(const boost::filesystem::path& from,
                                      const boost::filesystem::path& to);
 
+std::vector<std::string> GetDirectoryList(const boost::filesystem::path& cwd);
+
 }  // namespace common_installer
 
 #endif  // COMMON_UTILS_FILE_UTIL_H_
index 831c27f..7e0b78a 100644 (file)
@@ -5,7 +5,7 @@
 #include "common/utils/user_util.h"
 
 #include <manifest_parser/utils/logging.h>
-#include <sessiond.h>
+#include <tzplatform_config.h>
 
 #include <boost/filesystem/path.hpp>
 
@@ -17,6 +17,7 @@
 
 #include <vector>
 
+#include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
 
 namespace bf = boost::filesystem;
@@ -29,6 +30,8 @@ const int32_t kGRBufSize = sysconf(_SC_GETGR_R_SIZE_MAX);
 const int kRetryMax = 5;
 const int kRetryDelay = 1000000 / 2;
 
+const char kSubsessionDir[] = "subsession";
+
 }
 
 namespace common_installer {
@@ -179,25 +182,20 @@ std::string GetGroupNameByGid(gid_t gid) {
 }
 
 std::vector<std::string> GetLightUserList(uid_t uid) {
-  int user_count = 0;
-  subsession_user_t* user_list = nullptr;
-  int ret = subsession_get_user_list(
-      static_cast<int>(uid), &user_list, &user_count);
-  if (ret != TIZEN_ERROR_NONE) {
-    LOG(ERROR) << "Failed to get light user list : " << ret;
+  std::string username = GetUsernameByUid(uid);
+  if (username.empty()) {
+    LOG(ERROR) << "Failed to get user name of uid: " << uid;
     return {};
   }
 
-  std::vector<std::string> result_list;
-  for (int i = 0; i < user_count; i++) {
-    if (strlen(user_list[i]) == 0)
-      continue;
-
-    result_list.emplace_back(user_list[i]);
-  }
+  tzplatform_set_user(uid);
+  bf::path subsession_dir =
+      bf::path(tzplatform_getenv(TZ_USER_HOME)) / kSubsessionDir;
+  tzplatform_reset_user();
 
-  std::free(user_list);
-  return result_list;
+  // Get subsuession user list by directory name instead of using sessiond API
+  // due to performance issue
+  return GetDirectoryList(subsession_dir);
 }
 
 }  // namespace common_installer