2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <sys/types.h>
28 #include "path_manager.h"
29 #include "plugin_manager.h"
32 static const char* __TIZEN_API_PATH_KEY = "db/dotnet/tizen_api_path";
35 #define __STR(x) __XSTR(x)
36 static const char* __DEVICE_API_DIR = __STR(DEVICE_API_DIR);
37 static const char* __RUNTIME_DIR = __STR(RUNTIME_DIR);
38 static const char* __NATIVE_LIB_DIR = __STR(NATIVE_LIB_DIR);
39 static const char* __READ_ONLY_APP_UPDATE_DIR = __STR(READ_ONLY_APP_UPDATE_DIR);
44 // /appRoot/lib/{Architecture}/xxxxx.so
45 static std::string getExtraNativeLibDirs(const std::string& appRoot)
47 std::string candidate = concatPath(appRoot, "lib/" ARCHITECTURE_IDENTIFIER);
48 if (!strncmp(ARCHITECTURE_IDENTIFIER, "arm64", 5)) {
49 candidate = candidate + ":" + concatPath(appRoot, "lib/aarch64");
50 } else if (!strncmp(ARCHITECTURE_IDENTIFIER, "armel", 5)) {
51 candidate = candidate + ":" + concatPath(appRoot, "lib/arm");
57 void PathManager::updateAppRelatedPath(const std::string& appRootPath, const std::string& appNIRootPath)
59 std::string appBinPath = concatPath(appRootPath, "bin");
60 std::string appLibPath = concatPath(appRootPath, "lib");
62 std::string appNIBinPath = concatPath(concatPath(appNIRootPath, "bin"), APP_NI_SUB_DIR);
63 std::string appNILibPath = concatPath(concatPath(appNIRootPath, "lib"), APP_NI_SUB_DIR);
65 appTacPath = concatPath(appBinPath, TAC_SYMLINK_SUB_DIR);
66 appPaths = appRootPath + ":" + appBinPath + ":" + appLibPath + ":" + appTacPath;
67 appNIPaths = appNIBinPath + ":" + appNILibPath + ":" + appTacPath;
69 if (!extraDllPaths.empty()) {
70 appPaths = appPaths + ":" + extraDllPaths;
71 appNIPaths = appNIPaths + ":" + extraDllPaths;
75 PathManager::PathManager() :
80 runtimePath = getAbsolutePath(__RUNTIME_DIR);
81 platformAssembliesPaths.push_back(runtimePath);
84 char* tmp = vconf_get_str(__TIZEN_API_PATH_KEY);
86 tizenfxPath = std::string(tmp);
87 _DBG("Device API Directory is set by vconf : %s", tmp);
90 tizenfxPath = getAbsolutePath(__DEVICE_API_DIR);
92 platformAssembliesPaths.push_back(tizenfxPath);
93 platformAssembliesPaths.push_back(tizenfxPath + "/ref");
95 // set temporal application root path for candidate process
96 rootFD = open("/proc/self", O_DIRECTORY);
98 _ERR("Failed to open /proc/self");
99 throw std::ios_base::failure("Fail to open /proc/self");
102 // set temporal application root path for native image
103 niRootFD = open("/proc/self", O_DIRECTORY);
105 _ERR("Failed to open /proc/self");
106 throw std::ios_base::failure("Fail to open /proc/self");
109 std::string fdPath = "/proc/" + std::to_string(getpid()) + "/fd/";
110 appRootPath = fdPath + std::to_string(rootFD);
111 appNIRootPath = fdPath + std::to_string(niRootFD);
113 updateAppRelatedPath(appRootPath, appNIRootPath);
115 // Set native library searching path
116 nativeDllSearchingPaths = runtimePath + ":" + __NATIVE_LIB_DIR + ":" +
117 concatPath(appRootPath, "bin") + ":" + concatPath(appRootPath, "lib") + ":" +
118 getExtraNativeLibDirs(appRootPath);
120 _INFO("Path manager created successfully");
123 PathManager::~PathManager()
125 _INFO("Path manager destroyed");
128 // paths: ":" separated muliple path.
129 void PathManager::addPlatformAssembliesPaths(const std::string& paths, bool isHighPriority)
131 std::vector<std::string>::iterator it;
132 std::vector<std::string> pathVec;
133 splitPath(paths, pathVec);
135 for (unsigned int i = 0; i < pathVec.size(); i++) {
136 pathVec[i] = getAbsolutePath(pathVec[i]);
139 if (isHighPriority) {
140 it = platformAssembliesPaths.begin();
142 it = platformAssembliesPaths.end();
145 platformAssembliesPaths.insert(it, pathVec.begin(), pathVec.end());
148 void PathManager::addNativeDllSearchingPaths(const std::string& paths, bool isHighPriority)
150 if (isHighPriority) {
151 nativeDllSearchingPaths = paths + ":" + nativeDllSearchingPaths;
153 nativeDllSearchingPaths = nativeDllSearchingPaths + ":" + paths;
157 void PathManager::setAppRootPath(const std::string& rootPath)
159 appRootPath = getAbsolutePath(rootPath);
161 // check readonly update directory eixst or not
162 std::string niRootPath = replaceAll(appRootPath, getBaseName(appRootPath), __READ_ONLY_APP_UPDATE_DIR);
163 if (isReadOnlyArea(appRootPath) && isDirectory(niRootPath)) {
164 appNIRootPath = getAbsolutePath(niRootPath);
166 appNIRootPath = appRootPath;
169 // override root path for application launch mode (candidate / standalone mode)
171 int tmpFD = open(appRootPath.c_str(), O_DIRECTORY);
172 dup3(tmpFD, rootFD, O_CLOEXEC);
177 // override ni root path
179 int tmpFD = open(appNIRootPath.c_str(), O_DIRECTORY);
180 dup3(tmpFD, niRootFD, O_CLOEXEC);
185 updateAppRelatedPath(appRootPath, appNIRootPath);
188 // paths: ":" separated muliple path.
189 void PathManager::setExtraDllPaths(const char* paths)
191 extraDllPaths = std::string(paths);
192 if (!extraDllPaths.empty()) {
193 appPaths = appPaths + ":" + extraDllPaths;
194 appNIPaths = appNIPaths + ":" + extraDllPaths;
198 const std::string& PathManager::getRuntimePath()
203 const std::string& PathManager::getTizenFXPath()
208 // return platform assembly paths
209 const std::vector<std::string>& PathManager::getPlatformAssembliesPaths()
211 return platformAssembliesPaths;
214 // return app root path
215 const std::string& PathManager::getAppRootPath()
220 // return .tac_symlink path
221 const std::string& PathManager::getAppTacPath()
226 // return dll searching paths for app
227 const std::string& PathManager::getAppPaths()
232 // return ni dll searching paths for app
233 const std::string& PathManager::getAppNIPaths()
238 // return native dll searching paths for app
239 const std::string& PathManager::getNativeDllSearchingPaths()
241 return nativeDllSearchingPaths;