Mount gadget resource paths for NUIGadget
[platform/core/appfw/launchpad.git] / src / lib / launchpad-glib / util.cc
index e13ff46..b5861f6 100644 (file)
@@ -95,6 +95,20 @@ void SetRegionFormatEnvironments() {
   setenv("LC_IDENTIFICATION", region, 1);
 }
 
+void SetGadgetPkgIdsEnvironments(const tizen_base::Bundle& b) {
+  auto gadget_pkgids = b.GetStringArray(kAulMountGadgetPkgIds);
+  if (gadget_pkgids.empty()) return;
+
+  std::string pkgids;
+  for (auto& pkgid : gadget_pkgids) {
+    if (!pkgids.empty()) pkgids += ":";
+
+    pkgids += pkgid;
+  }
+
+  setenv("GADGET_PKGIDS", pkgids.c_str(), 1);
+}
+
 #ifdef TIZEN_FEATURE_SET_PERSONALITY_32
 static void SetExecutionDomain() {
   int ret = personality(PER_LINUX32);
@@ -241,7 +255,7 @@ class TepMountChecker : public DBus {
   std::vector<std::string> paths_;
 };
 
-void MountDirectories(const std::vector<std::string>& srcs,
+int MountDirectories(const std::vector<std::string>& srcs,
     const std::string& dest) {
   std::string opt = "lowerdir=" + dest;
   for (auto& src : srcs)
@@ -251,6 +265,8 @@ void MountDirectories(const std::vector<std::string>& srcs,
   int ret = mount(nullptr, dest.c_str(), "overlay", MS_RDONLY, opt.c_str());
   if (ret != 0)
     _E("mount() is failed. dest(%s), errno(%d)", dest.c_str(), errno);
+
+  return ret;
 }
 
 class ExternalPackage : public DBus {
@@ -407,6 +423,7 @@ void Util::SetEnvironments(const AppInfo* app_info) {
 
   setenv("GCOV_PREFIX", "/tmp", 1);
   setenv("DALI_DISABLE_PARTIAL_UPDATE", "0", 1);
+  SetGadgetPkgIdsEnvironments(b);
 }
 
 void Util::DeleteSocketPath(pid_t pid, uid_t uid) {
@@ -467,6 +484,16 @@ int Util::MountResourceDirectories(const AppInfo* app_info) {
   return 0;
 }
 
+int Util::MountGadgetDirectories(const tizen_base::Bundle& b) {
+  auto gadget_paths = b.GetStringArray(kAulMountGadgetPaths);
+  if (!gadget_paths.empty()) {
+    auto root_path = b.GetString(kAulRootPath);
+    return MountDirectories(gadget_paths, root_path + "/bin");
+  }
+
+  return 0;
+}
+
 int Util::WaitTepMount(const AppInfo* app_info) {
   if (app_info->GetBundle().GetType(kAulTepPath) == BUNDLE_TYPE_NONE)
     return 0;