Fix library and gadget mount 59/320659/3
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 20 Nov 2024 11:01:16 +0000 (20:01 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 21 Nov 2024 04:35:28 +0000 (04:35 +0000)
The library and gadget resources should be mounted to '/bin/.res_mount'.

Change-Id: I47082f8b81b96ad0dce3abbbfd02e58db80e7e66
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/app_executor.cc
src/launchpad-process-pool/loader_mount.cc
src/lib/launchpad-core/util.cc
src/lib/launchpad-core/util.hh
src/lib/launchpad/step_prepare_execution.cc

index feca783f0800b4d8425076e055bef7a11be7932a..3026cbf65a167cb4e339c11f4f2144c3f978b3f3 100644 (file)
@@ -237,13 +237,12 @@ int AppExecutor::StepEnableTrustAnchor() {
 }
 
 int AppExecutor::StepMountResDir() {
-  int ret = Util::MountGadgetDirectories(app_info_->GetBundle());
+  int ret = Util::MountGadgetAndLibrary(app_info_->GetBundle());
   if (ret != 0) {
-    _E("Failed to mount gadget resources");
+    _E("Failed to mount gadget and library resources");
     return ret;
   }
 
-  Util::MountLibraryDirectories(app_info_->GetBundle());
   return Util::MountResourceDirectories(app_info_);
 }
 
index a0a1b5f250bd0488e3a0d1d701a0849ae8ea15b6..e368780c23f9a5993f01efb2dda56361e29827b1 100644 (file)
@@ -80,11 +80,7 @@ int LoaderMount::Mount(pid_t pid, const AppInfo* app_info) {
 
   int ret = ChangeMountNamespace(pid);
   if (ret == 0) {
-    if (b.GetType(kAulMountGadgetPaths) != BUNDLE_TYPE_NONE)
-      ret |= Util::MountGadgetDirectories(b);
-    if (b.GetType(kAulMountLibDir) != BUNDLE_TYPE_NONE)
-      ret |= Util::MountLibraryDirectories(b);
-
+    ret = Util::MountGadgetAndLibrary(b);
     ChangeMountNamespace(launchpad_ppid_);
   }
 
index d24bb5a34d508661cbdba20918eb8f3c20f3721b..e442f15cc3d010d62113e7baa8ebc0a593988560 100644 (file)
@@ -516,37 +516,33 @@ int Util::MountResourceDirectories(const AppInfo* app_info) {
   return 0;
 }
 
-int Util::MountLibraryDirectories(const tizen_base::Bundle& b) {
-  auto lib_dir = ModifyDirectories(b.GetStringArray(kAulMountLibDir));
-  if (!lib_dir.empty()) {
-    auto root_path = b.GetString(kAulRootPath);
+int Util::MountGadgetAndLibrary(const tizen_base::Bundle& b) {
+  auto lib_paths = ModifyDirectories(b.GetStringArray(kAulMountLibDir));
+  auto gadget_paths = ValidateAndModifyGadgetPaths(
+        b.GetStringArray(kAulMountGadgetPaths));
+  if (lib_paths.empty() && gadget_paths.empty()) return 0;
+
+  auto root_path = b.GetString(kAulRootPath);
+  auto app_type = b.GetString(kAulAppType);
+  if (app_type.find("dotnet") != std::string::npos) {
     auto dest = root_path + "/bin/.res_mount/";
-    if (access(dest.c_str(), F_OK) != 0) {
-      auto app_type = b.GetString(kAulAppType);
-      if (app_type.find("dotnet") != std::string::npos)
-        dest = root_path + "/bin/";
-      else
-        dest = root_path + "/lib/";
-    }
-
-    MountDirectories(lib_dir, dest);
-  }
+    if (access(dest.c_str(), F_OK) != 0)
+      dest = root_path + "/bin/";
 
-  return 0;
-}
+    std::vector<std::string> source;
+    if (!gadget_paths.empty())
+      source.insert(source.end(), gadget_paths.begin(), gadget_paths.end());
 
-int Util::MountGadgetDirectories(const tizen_base::Bundle& b) {
-  auto gadget_paths = b.GetStringArray(kAulMountGadgetPaths);
-  if (!gadget_paths.empty()) {
-    gadget_paths = ValidateAndModifyGadgetPaths(gadget_paths);
-    auto root_path = b.GetString(kAulRootPath);
-    auto dest = root_path + "/bin/.res_mount/";
-    if (access(dest.c_str(), F_OK) != 0) dest = root_path + "/bin/";
+    if (!lib_paths.empty())
+      source.insert(source.end(), lib_paths.begin(), lib_paths.end());
 
-    return MountDirectories(gadget_paths, dest);
+    return MountDirectories(source, dest);
   }
 
-  return 0;
+  if (lib_paths.empty()) return 0;
+
+  auto dest = root_path + "/lib/";
+  return MountDirectories(lib_paths, dest);
 }
 
 int Util::WaitTepMount(const AppInfo* app_info) {
index 31f2d44ffb18e47b52edc0f980271f380d590328..ed470a35212ca68a23dd18e22e736b3fdd624b2d 100644 (file)
@@ -58,7 +58,7 @@ class EXPORT_API Util {
   static void DeleteSocketPath(pid_t pid, uid_t uid);
   static int EnableExternalPackage(const AppInfo* app_info);
   static int MountResourceDirectories(const AppInfo* app_info);
-  [[nodiscard]] static int MountGadgetDirectories(const tizen_base::Bundle& b);
+  static int MountGadgetAndLibrary(const tizen_base::Bundle& b);
   static int WaitTepMount(const AppInfo* app_info);
   static std::string GetLibDirectory(const std::string& app_path);
   static void CloseAllFds(const std::vector<int>& except_fds = {});
@@ -66,7 +66,6 @@ class EXPORT_API Util {
   static int PrepareAppIdFile(const AppInfo* app_info);
   static int SendCmdToAmd(enum AmdCmd cmd);
   static int SendCmdToAmd(enum AmdCmd cmd, bundle* request, int opt);
-  static int MountLibraryDirectories(const tizen_base::Bundle& b);
   static std::vector<std::string> Split(const std::string& str,
                                         const std::string& delim);
   static std::string ToUpper(std::string str);
index c9262a9c423edbbcf7d576e0a2501a0f1e8bc262..da292319fe4191ad4b32bc2c3dca326f0c040832 100644 (file)
@@ -99,13 +99,8 @@ int StepPrepareExecution::TrustAnchorLaunch(AppInfo* app_info) {
 
 int StepPrepareExecution::MountResourceDirectories(AppInfo* app_info) {
   if (getenv("LOADER_MOUNT") == nullptr) {
-    if (Util::MountGadgetDirectories(app_info->GetBundle()) != 0) {
-      _E("Failed to mount gadget resources");
-      return -1;
-    }
-
-    if (Util::MountLibraryDirectories(app_info->GetBundle()) != 0) {
-      _E("Failed to mount library direstories");
+    if (Util::MountGadgetAndLibrary(app_info->GetBundle()) != 0) {
+      _E("Failed to mount gadget & library resources");
       return -1;
     }
   }