The app-defined-loader uses the launchpad library.
This patch removes codes of lib/common directory.
Change-Id: Ied95a2cc31afb66796a47e4108af81fb1632f709
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src APP_DEFINED_LOADER_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../lib/common/src
- LIB_COMMON_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_DEFINED_LOADER_SRCS)
-ADD_EXECUTABLE(${TARGET_APP_DEFINED_LOADER}
- ${APP_DEFINED_LOADER_SRCS}
- ${LIB_COMMON_SRCS})
+ADD_EXECUTABLE(${TARGET_APP_DEFINED_LOADER} ${APP_DEFINED_LOADER_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_DEFINED_LOADER} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../)
IF(_TIZEN_FEATURE_PRELINK)
MESSAGE(STATUS "prelink enable")
SET_TARGET_PROPERTIES(${TARGET_APP_DEFINED_LOADER} PROPERTIES
SKIP_BUILD_RPATH TRUE)
-TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_DEFINED_LOADER} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/../lib/common/inc)
-TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_DEFINED_LOADER} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/../lib/launchpad/inc)
-
APPLY_PKG_CONFIG(${TARGET_APP_DEFINED_LOADER} PUBLIC
AUL_DEPS
BUNDLE_DEPS
LIBSYSTEMD_DEPS
)
-TARGET_LINK_LIBRARIES(${TARGET_APP_DEFINED_LOADER} PRIVATE ${TARGET_LAUNCHPAD})
+TARGET_LINK_LIBRARIES(${TARGET_APP_DEFINED_LOADER} PRIVATE
+ ${TARGET_LAUNCHPAD} ${TARGET_LAUNCHPAD_GLIB})
# To support 2.x applications which use their own shared libraries.
# Since we cannot set LD_LIBRARY_PATH directly by security issue, we make the
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <Ecore.h>
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <dlfcn.h>
+#include <launchpad.h>
+#include <linux/limits.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include <memory>
+#include <vector>
+
+#include <aul_keys.hh>
+#include <ini_parser.hh>
+#include <plugin.hh>
+#include <procfs.hh>
+#include <user_tracer.hh>
+#include <util.hh>
+
+#include "app-defined-loader/log-private.hh"
+
+namespace launchpad {
+namespace loader {
+namespace {
+
+const char PATH_CONF[] = "/usr/share/aul/app-defined-loader.conf";
+const char SECTION_MEMORY[] = "Memory";
+const char KEY_THRESHOLD[] = "Threshold";
+const uint64_t DEFAULT_THRESHOLD = 25600; // kB
+const char kLoaderTypeSw[] = "sw-loader";
+const char kLoaderTypeHw[] = "hw-loader";
+const char kLoaderType[] = "loader_type";
+
+} // namespace
+
+class AppDefinedLoader {
+ public:
+ AppDefinedLoader(int argc, char** argv) : argc_(argc), argv_(argv) {
+ lifecycle_cb_ = std::make_shared<loader_lifecycle_callback_s>();
+ lifecycle_cb_->create = OnCreate;
+ lifecycle_cb_->prelaunch = nullptr;
+ lifecycle_cb_->launch = OnLaunch;
+ lifecycle_cb_->terminate = OnTerminate;
+
+ adapter_ = std::make_shared<loader_adapter_s>();
+ adapter_->loop_begin = OnLoopBegin;
+ adapter_->loop_quit = OnLoopQuit;
+ adapter_->add_fd = OnAddFd;
+ adapter_->remove_fd = OnRemoveFd;
+
+ IniParser parser(PATH_CONF);
+ auto value = parser.Get(SECTION_MEMORY, KEY_THRESHOLD);
+ if (!value.empty())
+ threshold_ = static_cast<uint64_t>(std::stoi(value));
+ else
+ _W("Failed to get threshold");
+ }
+
+ ~AppDefinedLoader() {
+ _W("app defined loader destroyed");
+ }
+
+ std::shared_ptr<loader_lifecycle_callback_s> GetLifeCycle() {
+ return lifecycle_cb_;
+ }
+
+ std::shared_ptr<loader_adapter_s> GetAdapter() {
+ return adapter_;
+ }
+
+ void SetFdHandler(Ecore_Fd_Handler* fd_handler) {
+ fd_handler_ = fd_handler;
+ }
+
+ Ecore_Fd_Handler* GetFdHandler() {
+ return fd_handler_;
+ }
+
+ void SetReceiver(loader_receiver_cb receiver) {
+ receiver_cb_ = receiver;
+ }
+
+ loader_receiver_cb GetReceiver() {
+ return receiver_cb_;
+ }
+
+ int Run() {
+ return launchpad_loader_main(argc_, argv_, GetLifeCycle().get(),
+ GetAdapter().get(), this);
+ }
+
+ private:
+ void PreloadLib(tizen_base::Bundle data) {
+ std::vector<std::string> so_array = data.GetStringArray("preload");
+ if (so_array.size() == 0)
+ return;
+
+ for (auto& i : so_array) {
+ if (i.empty())
+ continue;
+ void* handle = dlopen(i.c_str(), RTLD_NOW | RTLD_NODELETE);
+ if (handle == nullptr)
+ _E("fail to load : %s, err : %s", i.c_str(), dlerror());
+ else
+ _D("preload %s# - handle : %p", i.c_str(), handle);
+
+ uint64_t pss;
+ launchpad::Procfs::GetPssMemory(getpid(), &pss);
+ if (pss > threshold_) {
+ _W("Pss(%llu) is over threshold(%llu)", pss, threshold_);
+ break;
+ }
+ }
+ }
+
+ static void OnCreate(bundle* extra, int type, void* user_data) {
+ _I("on create");
+ AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
+ tizen_base::Bundle ex = tizen_base::Bundle(extra, false, false);
+ std::string loader_type = ex.GetString(kLoaderType);
+ if (loader_type.empty()) {
+ _E("No loader type");
+ return;
+ }
+
+ loader->PreloadLib(ex);
+ ecore_init();
+ setenv("AUL_LOADER_INIT", "1", 1);
+
+ if (loader_type == kLoaderTypeSw)
+ setenv("AUL_HWACC", "none", 1);
+ else if (loader_type == kLoaderTypeHw)
+ setenv("AUL_HWACC", "hw", 1);
+
+ int ret = launchpad::Plugin::PrepareApp(nullptr, ex);
+ if (ret != 0) {
+ _E("Plugin::PrepareApp() is failed. error(%d)", ret);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ static int OnLaunch(int argc, char** argv, const char* app_path,
+ const char* appid, const char* pkgid, const char* pkg_type,
+ void* user_data) {
+ _I("on launch");
+ bundle* kb = launchpad_loader_get_bundle();
+ if (kb == nullptr)
+ return 0;
+
+ tizen_base::Bundle data(kb, false, false);
+ std::string high_priority = data.GetString(launchpad::kAulHighPriority);
+ if (high_priority == "true")
+ launchpad_loader_set_priority(-12);
+
+ data.Delete(launchpad::kAulHighPriority);
+ return 0;
+ }
+
+ void DoExec(std::string libdir) {
+ _I("do exec");
+ char err_str[128];
+ if (access(argv_[0], F_OK | R_OK)) {
+ SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)",
+ argv_[0], errno, strerror_r(errno, err_str, sizeof(err_str)));
+ } else {
+ SECURE_LOGD("[candidate] Exec application (%s)", argv_[0]);
+ launchpad::Util::CloseAllFds();
+ if (!libdir.empty())
+ setenv("LD_LIBRARY_PATH", libdir.c_str(), 1);
+ unsetenv("AUL_LOADER_INIT");
+ unsetenv("AUL_HWACC");
+ if (execv(argv_[0], argv_) < 0) {
+ fprintf(stderr, "Failed to execute a file. path: %s, errno: %d(%s)\n",
+ argv_[0], errno, strerror_r(errno, err_str, sizeof(err_str)));
+ exit(EXIT_FAILURE);
+ }
+ }
+ }
+
+ int DoDlOpen(bool restore, std::string old_cwd, std::string libdir) {
+ launchpad::UserTracer::Print(
+ std::to_string(getpid()) + "|lib loading start");
+ _W("dlopen(%s) ++", argv_[0]);
+ void* handle = dlopen(argv_[0], RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE);
+ _W("dlopen(%s) --", argv_[0]);
+ if (handle == nullptr) {
+ _E("dlopen(%s) is failed. error(%s)", argv_[0], dlerror());
+ DoExec(libdir);
+ return -1;
+ }
+
+ launchpad::UserTracer::Print(std::to_string(getpid()) + "|lib loading end");
+ if (restore && chdir(old_cwd.c_str()))
+ _E("failed to chdir: %d", errno);
+
+ auto dl_main = reinterpret_cast<int (*)(int, char**)>(
+ dlsym(handle, "main"));
+ if (dl_main == nullptr) {
+ _E("dlsym not founded(%s). Please export 'main' function", dlerror());
+ dlclose(handle);
+ DoExec(libdir);
+ return -1;
+ }
+
+ _I("call main");
+ return dl_main(argc_, argv_);
+ }
+
+ static int OnTerminate(int argc, char** argv, void* user_data) {
+ SECURE_LOGD("[candidate] Launch real application (%s)", argv[0]);
+ char old_cwd[PATH_MAX] = {0, };
+ AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
+ loader->argc_ = argc;
+ loader->argv_ = argv;
+
+ if (getcwd(old_cwd, sizeof(old_cwd)) == nullptr) {
+ _E("getcwd() is failed");
+ loader->DoDlOpen(false, old_cwd, "");
+ } else {
+ auto lib_dir = launchpad::Util::GetLibDirectory(argv[0]);
+ if (lib_dir.empty()) {
+ return loader->DoDlOpen(false, old_cwd, "");
+ } else {
+ /* To support 2.x applications which use their own shared libraries.
+ * We set '-rpath' to make the dynamic linker looks in the CWD forcely,
+ * so here we change working directory to find shared libraries well.
+ */
+ bool restore = false;
+ if (chdir(lib_dir.c_str()))
+ _E("failed to chdir: %d", errno);
+ else
+ restore = true;
+ std::string libdir_str = std::move(lib_dir);
+ return loader->DoDlOpen(restore, old_cwd, libdir_str);
+ }
+ }
+ return -1;
+ }
+
+ static void OnLoopBegin(void* user_data) {
+ _I("on loop begin");
+ ecore_main_loop_begin();
+ }
+
+ static void OnLoopQuit(void* user_data) {
+ _I("on loop quit");
+ ecore_main_loop_quit();
+ }
+
+ static void OnAddFd(void* user_data, int fd, loader_receiver_cb receiver) {
+ AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
+ Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd,
+ (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR),
+ FdHandler, loader, nullptr, nullptr);
+ if (handler == nullptr) {
+ _E("fd_handler is NULL");
+ close(fd);
+ exit(-1);
+ }
+ _I("set handler done (%d)", fd);
+ loader->SetFdHandler(handler);
+ loader->SetReceiver(receiver);
+ }
+
+ static Eina_Bool FdHandler(void* user_data, Ecore_Fd_Handler* handler) {
+ _I("fd handler");
+ AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
+ int fd = ecore_main_fd_handler_fd_get(handler);
+ if (fd == -1) {
+ _E("[candidate] ECORE_FD_GET");
+ exit(-1);
+ }
+ if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) {
+ if (loader->GetReceiver())
+ loader->GetReceiver()(fd);
+ } else if (ecore_main_fd_handler_active_get(
+ handler, ECORE_FD_ERROR)) {
+ _E("[candidate] ECORE_FD_ERROR");
+ close(fd);
+ exit(-1);
+ }
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ static void OnRemoveFd(void* user_data, int fd) {
+ _I("remove fd");
+ AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
+ if (loader->GetFdHandler() == nullptr)
+ return;
+ ecore_main_fd_handler_del(loader->GetFdHandler());
+ loader->SetFdHandler(nullptr);
+ loader->SetReceiver(nullptr);
+ }
+
+ private:
+ std::shared_ptr<loader_lifecycle_callback_s> lifecycle_cb_ = nullptr;
+ std::shared_ptr<loader_adapter_s> adapter_ = nullptr;
+ loader_receiver_cb receiver_cb_ = nullptr;
+ Ecore_Fd_Handler* fd_handler_ = nullptr;
+ uint64_t threshold_ = DEFAULT_THRESHOLD;
+ int argc_;
+ char** argv_;
+};
+
+} // namespace loader
+} // namespace launchpad
+
+int main(int argc, char** argv) {
+ launchpad::loader::AppDefinedLoader loader(argc, argv);
+ return loader.Run();
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APP_DEFINED_LOADER_LOG_PRIVATE_HH_
+#define APP_DEFINED_LOADER_LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "APP_DEFINED_LOADER"
+
+#ifdef _E
+#undef _E
+#endif
+#define _E LOGE
+
+#ifdef _W
+#undef _W
+#endif
+#define _W LOGW
+
+#ifdef _I
+#undef _I
+#endif
+#define _I LOGI
+
+#ifdef _D
+#undef _D
+#endif
+#define _D LOGD
+
+#endif // APP_DEFINED_LOADER_LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <Ecore.h>
-#include <bundle_cpp.h>
-#include <bundle_internal.h>
-#include <dlfcn.h>
-#include <launchpad.h>
-#include <linux/limits.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <sys/prctl.h>
-
-#include <memory>
-#include <vector>
-
-#include "config.hh"
-#include "key.h"
-#include "launchpad_common.h"
-#include "launchpad_plugin.h"
-#include "launchpad_types.h"
-#include "log-private.hh"
-#include "proc.hh"
-
-#ifndef PR_TASK_PERF_USER_TRACE
-#define PR_TASK_PERF_USER_TRACE 666
-#endif
-
-namespace launchpad {
-
-namespace {
-const char PATH_CONF[] = "/usr/share/aul/app-defined-loader.conf";
-const char SECTION_MEMORY[] = "Memory";
-const char KEY_THRESHOLD[] = "Threshold";
-const uint32_t DEFAULT_THRESHOLD = 25600; // kB
-} // namespace
-
-class AppDefinedLoader {
- public:
- AppDefinedLoader(int argc, char** argv) : argc_(argc), argv_(argv) {
- lifecycle_cb_ = std::make_shared<loader_lifecycle_callback_s>();
- lifecycle_cb_->create = OnCreate;
- lifecycle_cb_->prelaunch = nullptr;
- lifecycle_cb_->launch = OnLaunch;
- lifecycle_cb_->terminate = OnTerminate;
-
- adapter_ = std::make_shared<loader_adapter_s>();
- adapter_->loop_begin = OnLoopBegin;
- adapter_->loop_quit = OnLoopQuit;
- adapter_->add_fd = OnAddFd;
- adapter_->remove_fd = OnRemoveFd;
-
- proc_ = std::make_unique<Proc>(getpid());
- Config conf(PATH_CONF);
- int threshold = conf.GetIntValue(SECTION_MEMORY, KEY_THRESHOLD);
- if (threshold > 0)
- threshold_ = static_cast<uint32_t>(threshold);
- else
- _W("Failed to get threshold");
- }
-
- ~AppDefinedLoader() {
- _W("app defined loader destroyed");
- }
-
- std::shared_ptr<loader_lifecycle_callback_s> GetLifeCycle() {
- return lifecycle_cb_;
- }
-
- std::shared_ptr<loader_adapter_s> GetAdapter() {
- return adapter_;
- }
-
- void SetFdHandler(Ecore_Fd_Handler* fd_handler) {
- fd_handler_ = fd_handler;
- }
-
- Ecore_Fd_Handler* GetFdHandler() {
- return fd_handler_;
- }
-
- void SetReceiver(loader_receiver_cb receiver) {
- receiver_cb_ = receiver;
- }
-
- loader_receiver_cb GetReceiver() {
- return receiver_cb_;
- }
-
- private:
- void PreloadLib(tizen_base::Bundle data) {
- std::vector<std::string> so_array = data.GetStringArray("preload");
- if (so_array.size() == 0)
- return;
-
- for (auto& i : so_array) {
- if (i.empty())
- continue;
- void* handle = dlopen(i.c_str(), RTLD_NOW | RTLD_NODELETE);
- if (handle == nullptr)
- _E("fail to load : %s, err : %s", i.c_str(), dlerror());
- else
- _D("preload %s# - handle : %p", i.c_str(), handle);
-
- uint32_t pss = proc_->GetPss();
- if (pss > threshold_) {
- _W("Pss(%u) is over threshold(%u)", pss, threshold_);
- break;
- }
- }
- }
-
- static void OnCreate(bundle* extra, int type, void* user_data) {
- _I("on create");
- AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
- tizen_base::Bundle ex = tizen_base::Bundle(extra, false, false);
- std::string loader_type = ex.GetString(KEY_LOADER_TYPE);
- if (loader_type.empty()) {
- _E("No loader type");
- return;
- }
-
- loader->PreloadLib(ex);
- ecore_init();
- setenv("AUL_LOADER_INIT", "1", 1);
-
- if (loader_type == LOADER_TYPE_SW)
- setenv("AUL_HWACC", "none", 1);
- else if (loader_type == LOADER_TYPE_HW)
- setenv("AUL_HWACC", "hw", 1);
-
- int ret = _launchpad_plugin_prepare_app(nullptr, extra);
- if (ret != 0) {
- _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret);
- exit(EXIT_FAILURE);
- }
- }
-
- static int OnLaunch(int argc, char** argv, const char* app_path,
- const char* appid, const char* pkgid, const char* pkg_type,
- void* user_data) {
- _I("on launch");
- bundle* kb = launchpad_loader_get_bundle();
- if (kb == nullptr)
- return 0;
-
- tizen_base::Bundle data(kb, false, false);
- std::string high_priority = data.GetString(AUL_K_HIGHPRIORITY);
- if (high_priority == "true")
- launchpad_loader_set_priority(-12);
- data.Delete(AUL_K_HIGHPRIORITY);
- return 0;
- }
-
- void DoExec(std::string libdir) {
- _I("do exec");
- char err_str[MAX_LOCAL_BUFSZ];
- if (access(argv_[LOADER_ARG_PATH], F_OK | R_OK)) {
- SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)",
- argv_[LOADER_ARG_PATH], errno,
- strerror_r(errno, err_str, sizeof(err_str)));
- } else {
- SECURE_LOGD("[candidate] Exec application (%s)",
- argv_[LOADER_ARG_PATH]);
- _close_all_fds();
- if (!libdir.empty())
- setenv("LD_LIBRARY_PATH", libdir.c_str(), 1);
- unsetenv("AUL_LOADER_INIT");
- unsetenv("AUL_HWACC");
- if (execv(argv_[LOADER_ARG_PATH], argv_) < 0) {
- fprintf(stderr, "Failed to execute a file. path: %s, errno: %d(%s)\n",
- argv_[LOADER_ARG_PATH], errno,
- strerror_r(errno, err_str, sizeof(err_str)));
- exit(EXIT_FAILURE);
- }
- }
- }
-
- int DoDlOpen(bool restore, std::string old_cwd, std::string libdir) {
- std::string hwc_message = std::to_string(getpid()) + "|lib loading start";
- prctl(PR_TASK_PERF_USER_TRACE, hwc_message.c_str(), hwc_message.size());
- _W("dlopen(%s) ++", argv_[LOADER_ARG_PATH]);
- void* handle = dlopen(argv_[LOADER_ARG_PATH],
- RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE);
- _W("dlopen(%s) --", argv_[LOADER_ARG_PATH]);
- if (handle == nullptr) {
- _E("dlopen(%s) is failed. error(%s)", argv_[LOADER_ARG_PATH], dlerror());
- DoExec(libdir);
- return -1;
- }
-
- hwc_message = std::to_string(getpid()) + "|lib loading end";
- prctl(PR_TASK_PERF_USER_TRACE, hwc_message.c_str(), hwc_message.size());
-
- if (restore && chdir(old_cwd.c_str()))
- _E("failed to chdir: %d", errno);
-
- auto dl_main = reinterpret_cast<int (*)(int, char**)>(
- dlsym(handle, "main"));
- if (dl_main == nullptr) {
- _E("dlsym not founded(%s). Please export 'main' function", dlerror());
- dlclose(handle);
- DoExec(libdir);
- return -1;
- }
-
- _I("call main");
- return dl_main(argc_, argv_);
- }
-
- static int OnTerminate(int argc, char** argv, void* user_data) {
- SECURE_LOGD("[candidate] Launch real application (%s)",
- argv[LOADER_ARG_PATH]);
- char old_cwd[PATH_MAX] = {0, };
- AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
- loader->argc_ = argc;
- loader->argv_ = argv;
-
- if (getcwd(old_cwd, sizeof(old_cwd)) == nullptr) {
- _E("getcwd() is failed");
- loader->DoDlOpen(false, old_cwd, "");
- } else {
- char* libdir = _get_libdir(argv[LOADER_ARG_PATH]);
- if (libdir == NULL) {
- return loader->DoDlOpen(false, old_cwd, "");
- } else {
- /* To support 2.x applications which use their own shared libraries.
- * We set '-rpath' to make the dynamic linker looks in the CWD forcely,
- * so here we change working directory to find shared libraries well.
- */
- bool restore = false;
- if (chdir(libdir))
- _E("failed to chdir: %d", errno);
- else
- restore = true;
- std::string libdir_str = std::string(libdir);
- free(libdir);
- return loader->DoDlOpen(restore, old_cwd, libdir_str);
- }
- }
- return -1;
- }
-
- static void OnLoopBegin(void* user_data) {
- _I("on loop begin");
- ecore_main_loop_begin();
- }
-
- static void OnLoopQuit(void* user_data) {
- _I("on loop quit");
- ecore_main_loop_quit();
- }
-
- static void OnAddFd(void* user_data, int fd, loader_receiver_cb receiver) {
- AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
- Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd,
- (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR),
- FdHandler, loader, nullptr, nullptr);
- if (handler == nullptr) {
- _E("fd_handler is NULL");
- close(fd);
- exit(-1);
- }
- _I("set handler done (%d)", fd);
- loader->SetFdHandler(handler);
- loader->SetReceiver(receiver);
- }
-
- static Eina_Bool FdHandler(void* user_data, Ecore_Fd_Handler* handler) {
- _I("fd handler");
- AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
- int fd = ecore_main_fd_handler_fd_get(handler);
- if (fd == -1) {
- _E("[candidate] ECORE_FD_GET");
- exit(-1);
- }
- if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) {
- if (loader->GetReceiver())
- loader->GetReceiver()(fd);
- } else if (ecore_main_fd_handler_active_get(
- handler, ECORE_FD_ERROR)) {
- _E("[candidate] ECORE_FD_ERROR");
- close(fd);
- exit(-1);
- }
- return ECORE_CALLBACK_CANCEL;
- }
-
- static void OnRemoveFd(void* user_data, int fd) {
- _I("remove fd");
- AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
- if (loader->GetFdHandler() == nullptr)
- return;
- ecore_main_fd_handler_del(loader->GetFdHandler());
- loader->SetFdHandler(nullptr);
- loader->SetReceiver(nullptr);
- }
-
- private:
- std::shared_ptr<loader_lifecycle_callback_s> lifecycle_cb_ = nullptr;
- std::shared_ptr<loader_adapter_s> adapter_ = nullptr;
- loader_receiver_cb receiver_cb_ = nullptr;
- Ecore_Fd_Handler* fd_handler_ = nullptr;
- std::unique_ptr<Proc> proc_;
- uint32_t threshold_ = DEFAULT_THRESHOLD;
- int argc_;
- char** argv_;
-};
-
-} // namespace launchpad
-
-int main(int argc, char** argv) {
- launchpad::AppDefinedLoader loader(argc, argv);
- return launchpad_loader_main(argc, argv,
- loader.GetLifeCycle().get(), loader.GetAdapter().get(), &loader);
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <climits>
-
-#include "config.hh"
-
-namespace launchpad {
-
-Config::Config(const std::string& path)
- : d_(iniparser_load(path.c_str()), iniparser_freedict) {
-}
-
-Config::~Config() = default;
-
-int Config::GetIntValue(const std::string& section,
- const std::string& key) const {
- std::string section_key = section + ":" + key;
-
- return iniparser_getint(d_.get(), section_key.c_str(), INT_MIN);
-}
-
-} // namespace launchpad
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CONFIG_HH_
-#define CONFIG_HH_
-
-#include <iniparser.h>
-
-#include <memory>
-#include <string>
-
-namespace launchpad {
-
-class Config {
- public:
- Config(const std::string& path);
- virtual ~Config();
-
- int GetIntValue(const std::string& section, const std::string& key) const;
-
- private:
- std::unique_ptr<dictionary, decltype(iniparser_freedict)*> d_;
-};
-
-} // namespace launchpad
-
-#endif // CONFIG_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef LOG_PRIVATE_HH_
-#define LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "APP_DEFINED_LOADER"
-
-#ifdef _E
-#undef _E
-#endif
-#define _E LOGE
-
-#ifdef _W
-#undef _W
-#endif
-#define _W LOGW
-
-#ifdef _I
-#undef _I
-#endif
-#define _I LOGI
-
-#ifdef _D
-#undef _D
-#endif
-#define _D LOGD
-
-#endif // LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <cstdio>
-#include <fstream>
-
-#include "log-private.hh"
-#include "proc.hh"
-
-namespace launchpad {
-
-Proc::Proc(int pid) : pid_(pid) {
-}
-
-Proc::~Proc() = default;
-
-uint32_t Proc::GetPss() const {
- uint32_t total_pss = 0;
- std::string path = "/proc/" + std::to_string(pid_) + "/smaps";
- std::ifstream stream(path);
- if (stream.is_open()) {
- std::string line;
- while (std::getline(stream, line)) {
- uint32_t pss = 0;
- if (std::sscanf(line.c_str(), "Pss: %u kB", &pss) == 1) {
- total_pss += pss;
- pss = 0;
- }
- }
- stream.close();
- }
-
- _I("Pss: %u kB", total_pss);
- return total_pss;
-}
-
-} // namespace launchpad
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef PROC_HH_
-#define PROC_HH_
-
-#include <stdint.h>
-
-namespace launchpad {
-
-class Proc {
- public:
- Proc(int pid);
- virtual ~Proc();
-
- uint32_t GetPss() const;
-
- private:
- int pid_;
-};
-
-} // namespace launchpad
-
-#endif // PROC_HH_
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __KEY_H__
-#define __KEY_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define AUL_K_STARTTIME "__AUL_STARTTIME__"
-#define AUL_K_EXEC "__AUL_EXEC__"
-#define AUL_K_PACKAGETYPE "__AUL_PACKAGETYPE__"
-#define AUL_K_APP_TYPE "__AUL_APP_TYPE__"
-#define AUL_K_HWACC "__AUL_HWACC__"
-#define AUL_K_APPID "__AUL_APPID__"
-#define AUL_K_PID "__AUL_PID__"
-#define AUL_K_TASKMANAGE "__AUL_TASKMANAGE__"
-#define AUL_K_INTERNAL_POOL "__AUL_INTERNAL_POOL__"
-#define AUL_K_PKGID "__AUL_PKGID_"
-#define AUL_K_DEBUG "__AUL_DEBUG__"
-#define AUL_K_COMP_TYPE "__AUL_COMP_TYPE__"
-#define AUL_K_CALLER_PID "__AUL_CALLER_PID__"
-#define AUL_K_LOADER_ID "__AUL_LOADER_ID__"
-#define AUL_K_LOADER_PATH "__AUL_LOADER_PATH__"
-#define AUL_K_LOADER_EXTRA "__AUL_LOADER_EXTRA__"
-#define AUL_K_WAYLAND_DISPLAY "__AUL_WAYLAND_DISPLAY__"
-#define AUL_K_WAYLAND_WORKING_DIR "__AUL_WAYLAND_WORKING_DIR__"
-#define AUL_K_ROOT_PATH "__AUL_ROOT_PATH__"
-#define AUL_K_API_VERSION "__AUL_API_VERSION__"
-#define AUL_K_LOADER_NAME "__AUL_LOADER_NAME__"
-#define AUL_K_SDK "__AUL_SDK__"
-#define AUL_K_ORG_CALLER_PID "__AUL_ORG_CALLER_PID__"
-#define AUL_K_HIGHPRIORITY "__AUL_HIGHPRIORITY__"
-#define AUL_K_IS_GLOBAL "__AUL_IS_GLOBAL__"
-#define AUL_K_TEP_PATH "__AUL_TEP_PATH__"
-#define AUL_K_IS_INSTALLED "__AUL_IS_INSTALLED__"
-#define AUL_K_INSTALLED_STORAGE "__AUL_INSTALLED_STORAGE__"
-#define AUL_K_MOUNT_GLOBAL_RES_DIR "__AUL_MOUNT_GLOBAL_RES_DIR__"
-#define AUL_K_MOUNT_ALLOWED_RES_DIR "__AUL_MOUNT_ALLOWED_RES_DIR__"
-#define AUL_K_ENABLED_LIGHT_USER "__AUL_ENABLED_LIGHT_USER__"
-#define AUL_K_MOUNT_RES_PKGIDS "__AUL_MOUNT_RES_PKGIDS__"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __KEY_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LAUNCHPAD_COMMON_H__
-#define __LAUNCHPAD_COMMON_H__
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include <unistd.h>
-#include <ctype.h>
-#include <dlog.h>
-#include <bundle_internal.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <stdbool.h>
-#include <tzplatform_config.h>
-
-#ifdef LAUNCHPAD_LOG
-#undef LOG_TAG
-#define LOG_TAG "LAUNCHPAD"
-#endif
-
-#define MAX_PENDING_CONNECTIONS 10
-#define MAX_LOCAL_BUFSZ 128
-#define AUL_SOCK_MAXBUFF 131071
-#define LOADER_ARG_LEN 1024
-
-#define LAUNCHPAD_LAUNCH_SIGNAL 83
-#define LAUNCHPAD_DEAD_SIGNAL 61
-#define APP_STARTUP_SIGNAL 89
-
-#define PAD_LOADER_ID_STATIC 0
-#define PAD_LOADER_ID_DIRECT 1
-#define PAD_LOADER_ID_DYNAMIC_BASE 10
-
-#define KEY_LOADER_TYPE "loader_type"
-#define LOADER_TYPE_COMMON "common-loader"
-#define LOADER_TYPE_HW "hw-loader"
-#define LOADER_TYPE_SW "sw-loader"
-
-#undef _E
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-
-#undef _D
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-
-#undef _W
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-
-#undef _I
-#define _I(fmt, arg...) LOGI(fmt, ##arg)
-
-#define FREE_AND_NULL(x) do { \
- if (x) { \
- free(x); \
- x = NULL; \
- } \
-} while (0)
-
-#define ARRAY_SIZE(x) ((sizeof(x)) / sizeof(x[0]))
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- PAD_CMD_LAUNCH = 0,
- PAD_CMD_VISIBILITY = 10,
- PAD_CMD_ADD_LOADER = 11,
- PAD_CMD_REMOVE_LOADER = 12,
- PAD_CMD_MAKE_DEFAULT_SLOTS = 13,
- PAD_CMD_DEMAND = 14,
- PAD_CMD_PING = 15,
- PAD_CMD_UPDATE_APP_TYPE = 16,
- PAD_CMD_PREPARE_APP_DEFINED_LOADER = 17,
- PAD_CMD_CONNECT = 18,
-} pad_cmd_e;
-
-typedef struct _app_pkt_t {
- int cmd;
- int len;
- int opt;
- unsigned char data[1];
-} app_pkt_t;
-
-typedef struct {
- char *appid;
- char *app_path;
- char *original_app_path;
- char *pkg_type;
- char *app_type;
- char *hwacc;
- char *taskmanage;
- char *pkgid;
- char *comp_type;
- char *internal_pool;
- char *root_path;
- char *loader_name;
- bool global;
-} appinfo_t;
-
-void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *menu_info, int cmd);
-
-int _send_cmd_to_amd(int cmd);
-int _create_server_sock(const char *name);
-app_pkt_t *_recv_pkt_raw(int fd);
-app_pkt_t *_accept_recv_pkt_raw(int fd, int *clifd, struct ucred *cr);
-int _send_pkt_raw(int client_fd, app_pkt_t *pkt);
-int _connect_to_launchpad(int type, int id);
-int _set_sock_option(int fd, int cli);
-void _set_env(appinfo_t *menu_info, bundle *kb);
-char **_create_argc_argv(bundle *kb, int *margc);
-char *_get_libdir(const char *path);
-int _delete_sock_path(int pid, uid_t uid);
-
-appinfo_t *_appinfo_create(bundle *kb);
-void _appinfo_free(appinfo_t *menu_info);
-char *_appinfo_get_app_path(appinfo_t *menu_info);
-int _close_all_fds(void);
-void _get_cpu_idle(unsigned long long *total, unsigned long long *idle);
-int _setup_stdio(const char *ident);
-int _set_priority(int prio);
-int _wait_tep_mount(bundle *b);
-int _prepare_app_socket(void);
-int _enable_external_pkg(bundle *b, const char *pkgid, uid_t pkg_uid);
-int _verify_proc_caps(void);
-int _prepare_id_file(void);
-void _print_hwc_log(const char *format, ...);
-int _mount_res_dir(const char *menu_info, bundle *kb);
-
-#ifdef TIZEN_FEATURE_SET_PERSONALITY_32
-void _set_execution_domain(void);
-#endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */
-
-void _set_lang_env(void);
-void _set_region_env(void);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __LAUNCHPAD_COMMON_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LAUNCHPAD_PLUGIN_H__
-#define __LAUNCHPAD_PLUGIN_H__
-
-#include <bundle.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __LAUNCHPAD_PLUGIN_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LAUNCHPAD_PROC_H__
-#define __LAUNCHPAD_PROC_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio);
-
-int _proc_get_mem_pss(int pid, unsigned int *mem_pss);
-
-int _proc_get_attr(int pid, void *buf, unsigned int size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __LAUNCHPAD_PROC_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LAUNCHPAD_SOCKET_H__
-#define __LAUNCHPAD_SOCKET_H__
-
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define LAUNCHPAD_SOCKET_PATH_SIZE 108
-
-typedef struct socket_s *socket_h;
-
-int _socket_create(const char *path, bool client, socket_h *handle);
-
-int _socket_create_with_fd(int fd, socket_h *handle);
-
-int _socket_destroy(socket_h handle);
-
-int _socket_accept(socket_h handle, socket_h *client_socket);
-
-int _socket_get_fd(socket_h handle, int *fd);
-
-int _socket_set_fd(socket_h handle, int fd);
-
-int _socket_get_pid(socket_h handle, int *pid);
-
-int _socket_send(socket_h handle, const void *buf, unsigned int size);
-
-int _socket_read(socket_h handle, void *buf, unsigned int size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __LAUNCHPAD_SOCKET_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LAUNCHPAD_TYPES_H__
-#define __LAUNCHPAD_TYPES_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define SOCKET_PATH "/run/aul"
-#define LAUNCHPAD_LOADER_SOCKET_NAME ".launchpad-type"
-#define HYDRA_LOADER_SOCKET_NAME ".hydra-loader"
-#define CONNECT_RETRY_TIME (100 * 1000)
-#define CONNECT_RETRY_COUNT 3
-
-typedef enum loader_arg {
- LOADER_ARG_PATH,
- LOADER_ARG_TYPE,
- LOADER_ARG_ID,
- LOADER_ARG_HYDRA,
- LOADER_ARG_EXTRA,
- LOADER_ARG_DUMMY,
-} loader_arg_e;
-
-typedef enum hydra_cmd {
- LAUNCH_CANDIDATE,
- LAUNCH_CANDIDATE_WITH_ARGS,
-} hydra_cmd_e;
-
-typedef enum launchpad_loader_type {
- LAUNCHPAD_LOADER_TYPE_UNSUPPORTED = -1,
- LAUNCHPAD_LOADER_TYPE_USER = 1,
- LAUNCHPAD_LOADER_TYPE_DYNAMIC = 100,
- LAUNCHPAD_LOADER_TYPE_MAX
-} launchpad_loader_type_e;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __LAUNCHPAD_TYPES_H__ */
-
+++ /dev/null
-/*
- * Copyright (c) 2019 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LOG_PRIVATE_H__
-#define __LOG_PRIVATE_H__
-
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "LAUNCHPAD"
-
-#ifdef _E
-#undef _E
-#endif
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-
-#ifdef _D
-#undef _D
-#endif
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-
-#ifdef _W
-#undef _W
-#endif
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-
-#ifdef _I
-#undef _I
-#endif
-#define _I(fmt, arg...) LOGI(fmt, ##arg)
-
-#endif /* __LOG_PRIVATE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __PERF_H__
-#define __PERF_H__
-
-#ifdef PERF_ACTIVATE
-
-#include <time.h>
-
-static struct timespec __g_base_time = {
- .tv_sec = 0,
- .tv_nsec = 0
-};
-
-#define INIT_PERF(kb) do { \
- const char *tmp; \
- struct timespec tv; \
- tmp = bundle_get_val(kb, AUL_K_STARTTIME); \
- if (tmp != NULL) \
- sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_nsec); \
- else \
- clock_gettime(CLOCK_MONOTONIC, &tv); \
- __g_base_time.tv_sec = tv.tv_sec; \
- __g_base_time.tv_nsec = tv.tv_nsec; \
-} while (0)
-
-#define PERF(fmt, arg...) do { \
- struct timespec cur; \
- struct timespec res; \
- clock_gettime(CLOCK_MONOTONIC, &cur); \
- if (__g_base_time.tv_sec != 0) { \
- res->tv_sec = cur.tv_sec - __g_base_time.tv_sec; \
- res->tv_nsec = cur.tv_nsec - __g_base_time.tv_nsec; \
- printf("%c[1;31m[%s,%d] %ld sec %ld msec "fmt \
- " %c[0m\n", 27, __func__, \
- __LINE__, res.tv_sec, \
- res.tv_nsec / 1e6, ##arg, 27); \
- } \
-} while (0)
-
-#else
-
-#define INIT_PERF(kb)
-#define PERF(fmt, arg...)
-
-#endif
-
-#endif /* __PERF_H__ */
-
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef PREEXEC_ACTIVATE
-
-#include <dlfcn.h>
-#include <glib.h>
-#define PREEXEC_FILE SHARE_PREFIX"/preexec_list.txt"
-
-static int preexec_initialized;
-
-static GSList *preexec_list;
-
-typedef struct _preexec_list_t {
- char *pkg_type;
- char *so_path;
- int (*dl_do_pre_exe)(char *, char *);
-} preexec_list_t;
-
-static void __preexec_list_free(void)
-{
- GSList *iter = NULL;
- preexec_list_t *type_t;
-
- for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
- type_t = iter->data;
- if (type_t) {
- if (type_t->pkg_type)
- free(type_t->pkg_type);
- if (type_t->so_path)
- free(type_t->so_path);
- free(type_t);
- }
- }
- g_slist_free(preexec_list);
- preexec_initialized = 0;
-}
-
-static inline void __preexec_init(int argc, char **argv)
-{
- void *handle = NULL;
- FILE *preexec_file;
- char *saveptr = NULL;
- char line[MAX_LOCAL_BUFSZ];
- char *type = NULL;
- char *sopath = NULL;
- char *symbol = NULL;
- int (*func)(char *, char *) = NULL;
- preexec_list_t *type_t = NULL;
-
- preexec_file = fopen(PREEXEC_FILE, "rt");
- if (preexec_file == NULL) {
- _E("no preexec\n");
- return;
- }
-
- _D("preexec start\n");
-
- while (fgets(line, MAX_LOCAL_BUFSZ, preexec_file) > 0) {
- /* Parse each line */
- if (line[0] == '#' || line[0] == '\0')
- continue;
-
- type = strtok_r(line, ":\f\n\r\t\v ", &saveptr);
- if (type == NULL)
- continue;
- sopath = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
- if (sopath == NULL)
- continue;
- symbol = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
- if (symbol == NULL)
- continue;
-
- type_t = (preexec_list_t *) calloc(1, sizeof(preexec_list_t));
- if (type_t == NULL) {
- _E("no available memory\n");
- __preexec_list_free();
- fclose(preexec_file);
- return;
- }
-
- handle = dlopen(sopath, RTLD_GLOBAL | RTLD_LAZY | RTLD_NODELETE);
- if (handle == NULL) {
- free(type_t);
- continue;
- }
- _D("preexec %s %s# - handle : %p\n", type, sopath, handle);
-
- func = dlsym(handle, symbol);
- if (func == NULL) {
- _E("failed to get symbol type:%s path:%s\n",
- type, sopath);
- free(type_t);
- dlclose(handle);
- handle = NULL;
- continue;
- }
-
- type_t->pkg_type = strdup(type);
- if (type_t->pkg_type == NULL) {
- _E("no available memory\n");
- free(type_t);
- __preexec_list_free();
- fclose(preexec_file);
- return;
- }
- type_t->so_path = strdup(sopath);
- if (type_t->so_path == NULL) {
- _E("no available memory\n");
- free(type_t->pkg_type);
- free(type_t);
- __preexec_list_free();
- fclose(preexec_file);
- return;
- }
- type_t->dl_do_pre_exe = func;
-
- preexec_list = g_slist_append(preexec_list, (void *)type_t);
- }
-
- fclose(preexec_file);
- preexec_initialized = 1;
-}
-
-static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
- const char *app_path)
-{
- GSList *iter = NULL;
- preexec_list_t *type_t;
-
- if (!preexec_initialized || !pkg_type)
- return;
-
- for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
- type_t = iter->data;
- if (type_t) {
- if (!strcmp(pkg_type, type_t->pkg_type)) {
- if (type_t->dl_do_pre_exe != NULL) {
- type_t->dl_do_pre_exe((char *)pkg_name,
- (char *)app_path);
- _D("called dl_do_pre_exe() type: %s",
- pkg_type);
- } else {
- _E("no symbol for this type: %s",
- pkg_type);
- }
- }
- }
- }
-
-}
-
-#else
-
-static void __preexec_list_free(void)
-{
-}
-
-static inline void __preexec_init(int argc, char **argv)
-{
-}
-
-static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
- const char *app_path)
-{
-}
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/xattr.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <linux/limits.h>
-#include <unistd.h>
-#include <sys/capability.h>
-#include <tzplatform_config.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <systemd/sd-journal.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/personality.h>
-#include <sys/prctl.h>
-#include <dbus/dbus.h>
-#include <vconf.h>
-#include <dlog.h>
-#include <dlog-redirect-stdout.h>
-
-#include "launchpad_common.h"
-#include "launchpad_types.h"
-#include "key.h"
-
-#define MAX_PATH_LEN 1024
-#define MAX_CMD_BUFSZ 1024
-
-#define MAX_PENDING_CONNECTIONS 10
-#define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int) + sizeof(int))
-#define PATH_AMD_SOCK "/run/aul/daemons/.amd-sock"
-#define PATH_DEV_NULL "/dev/null"
-#define MAX_TEP_IS_MOUNT_RETRY_CNT 100
-#define MAX_PAYLOAD_SIZE (1024 * 1024 * 1)
-
-#define TEP_BUS_NAME "org.tizen.system.deviced"
-#define TEP_OBJECT_PATH "/Org/Tizen/System/DeviceD/Tzip"
-#define TEP_INTERFACE_NAME "org.tizen.system.deviced.Tzip"
-#define TEP_IS_MOUNTED_METHOD "IsMounted"
-
-#define APP2SD_BUS_NAME "org.tizen.app2sd"
-#define APP2SD_OBJECT_PATH "/org/tizen/app2sd"
-#define APP2SD_INTERFACE_NAME "org.tizen.app2sd"
-#define APP2SD_ONDEMANDSETUPINIT_METHOD "OndemandSetupInit"
-#define APP2SD_RETRY_MAX 5
-#define APP2SD_WAIT_USEC (1000000 / 2) /* 0.5 sec */
-
-#ifndef PR_TASK_PERF_USER_TRACE
-#define PR_TASK_PERF_USER_TRACE 666
-#endif
-
-void _get_cpu_idle(unsigned long long *total, unsigned long long *idle)
-{
- FILE *fp;
- int i;
- unsigned long long sum = 0;
- unsigned long long val;
- unsigned long long iv = 0;
- char buf[4] = { 0, };
-
- fp = fopen("/proc/stat", "rt");
-
- if (fp == NULL)
- return;
-
- if (fscanf(fp, "%3s", buf) == -1) {
- fclose(fp);
- return;
- }
-
- for (i = 0; i < 10; i++) {
- if (fscanf(fp, "%lld", &val) == -1) {
- fclose(fp);
- return;
- }
-
- if (sum + val < sum) {
- _E("overflow");
- fclose(fp);
- return;
- }
-
- sum += val;
- if (i == 3) /* idle */
- iv = val;
- }
-
- fclose(fp);
-
- *total = sum;
- *idle = iv;
-}
-
-int _set_sock_option(int fd, int cli)
-{
- struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */
- int size;
- int flag;
- int ret;
-
- size = AUL_SOCK_MAXBUFF;
- ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
- if (ret < 0) {
- _E("Failed to set SO_SNDBUF option on socket. errno(%d)",
- errno);
- return -1;
- }
-
- ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
- if (ret < 0) {
- _E("Failed to set SO_RCVBUF option on socket. errno(%d)",
- errno);
- return -1;
- }
-
- if (cli) {
- ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
- if (ret < 0) {
- _E("Failed to set SO_RCVTIMEO option on socket. " \
- "errno(%d)", errno);
- return -1;
- }
-
- flag = fcntl(fd, F_GETFD);
- flag |= FD_CLOEXEC;
- ret = fcntl(fd, F_SETFD, flag);
- if (ret < 0) {
- _E("Failed to manipulate fd(F_SETFD), errno(%d)",
- errno);
- return -1;
- }
- }
-
- return 0;
-}
-
-static int __parse_app_path(const char *arg, char *out, int out_size)
-{
- register int i;
- int state = 1;
- char *start_out = out;
-
- if (arg == NULL || out == NULL) {
- /* Handles null buffer*/
- return 0;
- }
-
- for (i = 0; out_size > 1; i++) {
- switch (state) {
- case 1:
- switch (arg[i]) {
- case ' ':
- case '\t':
- state = 5;
- break;
- case '\0':
- state = 7;
- break;
- case '\"':
- state = 2;
- break;
- case '\\':
- state = 4;
- break;
- default:
- *out = arg[i];
- out++;
- out_size--;
- break;
- }
- break;
- case 2: /* escape start*/
- switch (arg[i]) {
- case '\0':
- state = 6;
- break;
- case '\"':
- state = 1;
- break;
- default:
- *out = arg[i];
- out++;
- out_size--;
- break;
- }
- break;
- case 4: /* character escape*/
- if (arg[i] == '\0') {
- state = 6;
- } else {
- *out = arg[i];
- out++;
- out_size--;
- state = 1;
- }
- break;
- case 5: /* token*/
- if (out != start_out) {
- *out = '\0';
- out_size--;
- return i;
- }
- i--;
- state = 1;
- break;
- case 6:
- return -1; /* error*/
- case 7: /* terminate*/
- *out = '\0';
- out_size--;
- return 0;
- default:
- state = 6;
- break; /* error*/
- }
- }
-
- if (out_size == 1)
- *out = '\0';
-
- /* Buffer overflow*/
- return -2;
-}
-
-static int __create_client_socket(const char *path)
-{
- struct sockaddr_un addr = { 0, };
- int retry = CONNECT_RETRY_COUNT;
- int fd;
-
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd < 0) {
- _E("Failed to create socket(%s). errno(%d)", path, errno);
- return -1;
- }
-
- addr.sun_family = AF_UNIX;
- snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
- while (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- if (errno != ETIMEDOUT || retry <= 0) {
- _E("Failed to connect socket(%s). errno(%d)",
- path, errno);
- close(fd);
- return -1;
- }
-
- usleep(CONNECT_RETRY_TIME);
- retry--;
- _W("Retry(%d) to connect %s", retry, path);
- }
-
- return fd;
-}
-
-int _send_cmd_to_amd(int cmd)
-{
- app_pkt_t pkt = {0,};
- int ret;
- int fd;
-
- fd = __create_client_socket(PATH_AMD_SOCK);
- if (fd < 0)
- return -1;
-
- pkt.cmd = cmd;
- ret = send(fd, &pkt, sizeof(app_pkt_t), MSG_NOSIGNAL);
- if (ret <= 0) {
- _E("Failed to send cmd(%d), errno(%d)", cmd, errno);
- close(fd);
- return -ECOMM;
- }
-
- close(fd);
- return 0;
-}
-
-int _create_server_sock(const char *name)
-{
- struct sockaddr_un saddr;
- int fd;
-
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- /* support above version 2.6.27*/
- if (fd < 0) {
- if (errno == EINVAL) {
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) {
- _E("second chance - socket create error");
- return -1;
- }
- } else {
- _E("socket error");
- return -1;
- }
- }
-
- memset(&saddr, 0, sizeof(saddr));
- saddr.sun_family = AF_UNIX;
-
- snprintf(saddr.sun_path, sizeof(saddr.sun_path),
- "%s/daemons/%d/%s",
- SOCKET_PATH, getuid(), name);
- unlink(saddr.sun_path);
-
- if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
- _E("bind error");
- close(fd);
- return -1;
- }
-
- if (_set_sock_option(fd, 0) < 0) {
- _E("Failed to set sock option");
- close(fd);
- return -1;
- }
-
- if (listen(fd, 128) == -1) {
- _E("listen error");
- close(fd);
- return -1;
- }
-
- return fd;
-}
-
-app_pkt_t *_recv_pkt_raw(int fd)
-{
- int len;
- int ret;
- unsigned char buf[AUL_PKT_HEADER_SIZE];
- app_pkt_t *pkt;
- int cmd;
- int datalen;
- int opt;
-
-retry_recv:
- /* receive header(cmd, datalen) */
- len = recv(fd, buf, AUL_PKT_HEADER_SIZE, 0);
- if (len < 0) {
- if (errno == EINTR)
- goto retry_recv;
- }
-
- if (len < AUL_PKT_HEADER_SIZE) {
- _E("recv error");
- return NULL;
- }
- memcpy(&cmd, buf, sizeof(int));
- memcpy(&datalen, buf + sizeof(int), sizeof(int));
- memcpy(&opt, buf + sizeof(int) + sizeof(int), sizeof(int));
-
- if (datalen < 0 || datalen > MAX_PAYLOAD_SIZE) {
- _E("Invalid protocol. datalen(%d)", datalen);
- return NULL;
- }
-
- /* allocate for a null byte */
- pkt = (app_pkt_t *)calloc(1, AUL_PKT_HEADER_SIZE + datalen + 1);
- if (pkt == NULL) {
- _E("failed to alloc app_pkt_t");
- return NULL;
- }
- pkt->cmd = cmd;
- pkt->len = datalen;
- pkt->opt = opt;
-
- len = 0;
- while (len != pkt->len) {
- ret = recv(fd, pkt->data + len, pkt->len - len, 0);
- if (ret == 0) {
- _E("EOF. fd(%d), len(%d), pkt->len(%d)",
- fd, len, pkt->len);
- free(pkt);
- return NULL;
- }
-
- if (ret < 0) {
- _E("recv() is failed. fd(%d), len(%d), pkt->len(%d)",
- fd, len, pkt->len);
- free(pkt);
- return NULL;
- }
- len += ret;
- _D("recv len %d %d", len, pkt->len);
- }
-
- return pkt;
-}
-
-app_pkt_t *_accept_recv_pkt_raw(int fd, int *clifd, struct ucred *cr)
-{
- struct sockaddr_un aul_addr = { 0, };
- int sun_size = (int)sizeof(struct sockaddr_un);
- app_pkt_t *pkt;
- int newfd;
- int cl = (int)sizeof(struct ucred);
-
- newfd = accept(fd, (struct sockaddr *)&aul_addr,
- (socklen_t *) &sun_size);
- if (newfd == -1) {
- if (errno != EINTR)
- _E("accept error");
- return NULL;
- }
-
- if (getsockopt(newfd, SOL_SOCKET, SO_PEERCRED, cr,
- (socklen_t *) &cl) < 0) {
- _E("peer information error");
- close(newfd);
- return NULL;
- }
-
- if (_set_sock_option(newfd, 1) < 0) {
- _E("Failed to set sock option");
- close(newfd);
- return NULL;
- }
-
- pkt = _recv_pkt_raw(newfd);
- if (pkt == NULL) {
- _E("failed to receive pkt from client");
- close(newfd);
- return NULL;
- }
-
- *clifd = newfd;
- return pkt;
-}
-
-int _send_pkt_raw(int client_fd, app_pkt_t *pkt)
-{
- int send_ret = 0;
- int pkt_size = 0;
- int sent = 0;
-
- if (client_fd == -1 || pkt == NULL) {
- _E("arguments error!");
- return -1;
- }
-
- pkt_size = AUL_PKT_HEADER_SIZE + pkt->len;
-
- while (sent != pkt_size) {
- send_ret = send(client_fd, (char *)pkt + sent,
- pkt_size - sent, MSG_NOSIGNAL);
- if (send_ret == -1) {
- _E("send error! (%d)", errno);
- return -1;
- }
-
- sent += send_ret;
- _D("send(%d: ret: %d) : %d / %d",
- client_fd, send_ret, sent, pkt_size);
- }
-
- return 0;
-}
-
-appinfo_t *_appinfo_create(bundle *kb)
-{
- appinfo_t *menu_info;
- const char *ptr = NULL;
-
- menu_info = calloc(1, sizeof(appinfo_t));
- if (menu_info == NULL)
- return NULL;
-
- ptr = bundle_get_val(kb, AUL_K_APPID);
- if (ptr)
- menu_info->appid = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_EXEC);
- if (ptr)
- menu_info->app_path = strdup(ptr);
- if (menu_info->app_path != NULL)
- menu_info->original_app_path = strdup(menu_info->app_path);
- ptr = bundle_get_val(kb, AUL_K_PACKAGETYPE);
- if (ptr)
- menu_info->pkg_type = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_APP_TYPE);
- if (ptr)
- menu_info->app_type = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_HWACC);
- if (ptr)
- menu_info->hwacc = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_TASKMANAGE);
- if (ptr)
- menu_info->taskmanage = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_PKGID);
- if (ptr)
- menu_info->pkgid = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_COMP_TYPE);
- if (ptr)
- menu_info->comp_type = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_INTERNAL_POOL);
- if (ptr)
- menu_info->internal_pool = strdup(ptr);
- ptr = bundle_get_val(kb, AUL_K_ROOT_PATH);
- if (ptr)
- menu_info->root_path = strdup(ptr);
-
- ptr = bundle_get_val(kb, AUL_K_LOADER_NAME);
- if (ptr)
- menu_info->loader_name = strdup(ptr);
-
- ptr = bundle_get_val(kb, AUL_K_IS_GLOBAL);
- if (ptr && strcmp(ptr, "true") == 0)
- menu_info->global = true;
- else
- menu_info->global = false;
-
- if (!_appinfo_get_app_path(menu_info)) {
- _appinfo_free(menu_info);
- return NULL;
- }
-
- return menu_info;
-}
-
-char *_appinfo_get_app_path(appinfo_t *menu_info)
-{
- int i = 0;
- int path_len = -1;
- char *tmp_app_path;
-
- if (!menu_info || menu_info->app_path == NULL)
- return NULL;
-
- while (menu_info->app_path[i] != 0) {
- if (menu_info->app_path[i] == ' '
- || menu_info->app_path[i] == '\t') {
- path_len = i;
- break;
- }
- i++;
- }
-
- if (path_len == 0) {
- free(menu_info->app_path);
- menu_info->app_path = NULL;
- } else if (path_len > 0) {
- tmp_app_path = malloc(sizeof(char) * (path_len + 1));
- if (tmp_app_path == NULL)
- return NULL;
- snprintf(tmp_app_path, path_len + 1, "%s", menu_info->app_path);
- free(menu_info->app_path);
- menu_info->app_path = tmp_app_path;
- }
-
- return menu_info->app_path;
-}
-
-void _appinfo_free(appinfo_t *menu_info)
-{
- if (menu_info == NULL)
- return;
-
- if (menu_info->appid != NULL)
- free(menu_info->appid);
- if (menu_info->app_path != NULL)
- free(menu_info->app_path);
- if (menu_info->original_app_path != NULL)
- free(menu_info->original_app_path);
- if (menu_info->pkg_type != NULL)
- free(menu_info->pkg_type);
- if (menu_info->app_type != NULL)
- free(menu_info->app_type);
- if (menu_info->hwacc != NULL)
- free(menu_info->hwacc);
- if (menu_info->taskmanage != NULL)
- free(menu_info->taskmanage);
- if (menu_info->pkgid != NULL)
- free(menu_info->pkgid);
- if (menu_info->comp_type != NULL)
- free(menu_info->comp_type);
- if (menu_info->internal_pool != NULL)
- free(menu_info->internal_pool);
- if (menu_info->root_path != NULL)
- free(menu_info->root_path);
- if (menu_info->loader_name != NULL)
- free(menu_info->loader_name);
-
- free(menu_info);
-}
-
-static bool __validate_bundle_key(const char *key)
-{
- if (!key)
- return false;
-
- if (!strncmp(key, "__AUL_", strlen("__AUL_")))
- return false;
-
- if (!strncmp(key, "__APP_SVC_", strlen("__APP_SVC_")))
- return false;
-
- return true;
-}
-
-void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *menu_info, int cmd)
-{
- char *ptr;
- char exe[MAX_PATH_LEN];
- int flag;
- char key[256];
- char value[256];
-
- bundle_del(kb, AUL_K_APPID);
- bundle_del(kb, AUL_K_EXEC);
- bundle_del(kb, AUL_K_APP_TYPE);
- bundle_del(kb, AUL_K_PACKAGETYPE);
- bundle_del(kb, AUL_K_TASKMANAGE);
- bundle_del(kb, AUL_K_PKGID);
- bundle_del(kb, AUL_K_COMP_TYPE);
-
- /* Parse app_path to retrieve default bundle*/
- if (cmd == PAD_CMD_LAUNCH) {
- ptr = menu_info->original_app_path;
- flag = __parse_app_path(ptr, exe, sizeof(exe));
- if (flag > 0) {
- ptr += flag;
- SECURE_LOGD("parsing app_path: EXEC - %s", exe);
-
- do {
- flag = __parse_app_path(ptr, key, sizeof(key));
- if (flag <= 0)
- break;
- ptr += flag;
-
- flag = __parse_app_path(ptr, value,
- sizeof(value));
- if (flag < 0)
- break;
- ptr += flag;
-
- /*bundle_del(kb, key);*/
- if (__validate_bundle_key(key))
- bundle_add(kb, key, value);
- } while (flag > 0);
- } else if (flag == 0)
- _D("parsing app_path: No arguments");
- else
- _D("parsing app_path: Invalid argument");
- }
-}
-
-int _connect_to_launchpad(int type, int id)
-{
- char path[PATH_MAX];
- int client_pid;
- int send_ret;
- int fd;
-
- _D("[launchpad] enter, type: %d", type);
-
- snprintf(path, sizeof(path), "%s/daemons/%d/%s%d-%d",
- SOCKET_PATH, getuid(), LAUNCHPAD_LOADER_SOCKET_NAME,
- type, id);
- fd = __create_client_socket(path);
- if (fd < 0)
- return -1;
-
- client_pid = getpid();
- send_ret = send(fd, &client_pid, sizeof(client_pid), MSG_NOSIGNAL);
- _D("send(%d) : %d", client_pid, send_ret);
- if (send_ret == -1) {
- _E("send error(%d)", errno);
- close(fd);
- return -1;
- }
-
- SECURE_LOGD("[launchpad] done, connect fd: %d", fd);
- return fd;
-}
-
-#ifdef TIZEN_FEATURE_SET_PERSONALITY_32
-void _set_execution_domain(void)
-{
- char err_buf[1024];
- int res;
-
- res = personality(PER_LINUX32);
- if (res < 0) {
- _E("personality() failed, error: %d (%s)",
- errno,
- strerror_r(errno, err_buf, sizeof(err_buf)));
- }
-}
-#endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */
-
-void _set_lang_env(void)
-{
- const char *lang;
-
- lang = getenv("LANG");
- if (!lang) {
- lang = "en_US.UTF-8";
- setenv("LANG", lang, 1);
- }
-
- setenv("LANGUAGE", lang, 1);
- setenv("LC_MESSAGES", lang, 1);
- setenv("LC_ALL", lang, 1);
-}
-
-void _set_region_env(void)
-{
- const char *region;
-
- region = getenv("LC_CTYPE");
- if (!region) {
- region = "en_US.UTF-8";
- setenv("LC_CTYPE", region, 1);
- }
-
- setenv("LC_NUMERIC", region, 1);
- setenv("LC_TIME", region, 1);
- setenv("LC_COLLATE", region, 1);
- setenv("LC_MONETARY", region, 1);
- setenv("LC_PAPER", region, 1);
- setenv("LC_NAME", region, 1);
- setenv("LC_ADDRESS", region, 1);
- setenv("LC_TELEPHONE", region, 1);
- setenv("LC_MEASUREMENT", region, 1);
- setenv("LC_IDENTIFICATION", region, 1);
-}
-
-void _set_env(appinfo_t *menu_info, bundle *kb)
-{
- const char *str;
- char buf[MAX_LOCAL_BUFSZ];
-
- str = bundle_get_val(kb, AUL_K_STARTTIME);
- if (str != NULL)
- setenv("APP_START_TIME", str, 1);
-
- if (menu_info->hwacc != NULL)
- setenv("HWACC", menu_info->hwacc, 1);
- if (menu_info->taskmanage != NULL)
- setenv("TASKMANAGE", menu_info->taskmanage, 1);
- if (menu_info->root_path != NULL)
- setenv("AUL_ROOT_PATH", menu_info->root_path, 1);
- if (menu_info->appid != NULL)
- setenv("AUL_APPID", menu_info->appid, 1);
- if (menu_info->pkgid != NULL)
- setenv("AUL_PKGID", menu_info->pkgid, 1);
- if (menu_info->app_type != NULL)
- setenv("RUNTIME_TYPE", menu_info->app_type, 1);
-
- str = bundle_get_val(kb, AUL_K_WAYLAND_DISPLAY);
- if (str != NULL)
- setenv("WAYLAND_DISPLAY", str, 1);
-
- str = bundle_get_val(kb, AUL_K_WAYLAND_WORKING_DIR);
- if (str != NULL)
- setenv("XDG_RUNTIME_DIR", str, 1);
-
- str = bundle_get_val(kb, AUL_K_API_VERSION);
- if (str != NULL)
- setenv("TIZEN_API_VERSION", str, 1);
-
- snprintf(buf, sizeof(buf), "%d", getpid());
- setenv("AUL_PID", buf, 1);
- setenv("TIZEN_GLIB_CONTEXT", "0", 1);
-
- _set_lang_env();
- _set_region_env();
-#ifdef TIZEN_FEATURE_SET_PERSONALITY_32
- _set_execution_domain();
-#endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */
-
- setenv("GCOV_PREFIX", "/tmp", 1);
-}
-
-char **_create_argc_argv(bundle *kb, int *margc)
-{
- char **argv;
- int argc;
-
- argc = bundle_export_to_argv(kb, &argv);
-
- *margc = argc;
- return argv;
-}
-
-char *_get_libdir(const char *path)
-{
- char *path_dup;
- char buf[PATH_MAX];
- char *ptr;
-
- if (path == NULL)
- return NULL;
- path_dup = strdup(path);
- if (path_dup == NULL)
- return NULL;
- ptr = strrchr(path_dup, '/');
- if (ptr == NULL) {
- free(path_dup);
- return NULL;
- }
-
- *ptr = '\0';
-
- snprintf(buf, sizeof(buf), "%s/../lib/", path_dup);
- free(path_dup);
-
- if (access(buf, F_OK) == -1)
- return NULL;
-
- return strdup(buf);
-}
-
-static int __delete_dir(const char *path)
-{
- DIR *dp;
- struct dirent *dentry = NULL;
- char buf[PATH_MAX];
- struct stat statbuf;
- int ret;
-
- if (path == NULL)
- return -1;
-
- dp = opendir(path);
- if (dp == NULL)
- return -1;
-
- while ((dentry = readdir(dp)) != NULL) {
- if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
- continue;
-
- snprintf(buf, sizeof(buf), "%s/%s", path, dentry->d_name);
- ret = stat(buf, &statbuf);
- if (ret == 0) {
- if (S_ISDIR(statbuf.st_mode))
- __delete_dir(buf);
- else
- unlink(buf);
- }
- }
-
- rmdir(path);
- closedir(dp);
-
- return 0;
-}
-
-int _delete_sock_path(int pid, uid_t uid)
-{
- char path[PATH_MAX];
- int r;
-
- snprintf(path, sizeof(path), "/run/aul/apps/%d/%d", uid, pid);
- r = access(path, F_OK);
- if (r != 0) {
- if (errno != ENOENT)
- _E("Failed to access %s. errno(%d)", path, errno);
- } else {
- __delete_dir(path);
- }
-
- if (access(path, F_OK) == 0) {
- _E("Failed to delete %s", path);
- return -1;
- }
-
- return 0;
-}
-
-int _close_all_fds(void)
-{
- DIR *dp;
- struct dirent *dentry = NULL;
- int fd;
- int max_fd;
- int aul_fd = -1;
- const char *aul_listen_fd;
-
- aul_listen_fd = getenv("AUL_LISTEN_FD");
- if (aul_listen_fd)
- aul_fd = atoi(aul_listen_fd);
-
- dp = opendir("/proc/self/fd");
- if (dp == NULL) {
- /* fallback */
- max_fd = sysconf(_SC_OPEN_MAX);
- for (fd = 3; fd < max_fd; fd++) {
- if (fd != aul_fd)
- close(fd);
- }
-
- return 0;
- }
-
- while ((dentry = readdir(dp)) != NULL) {
- if (!isdigit(dentry->d_name[0]))
- continue;
-
- fd = atoi(dentry->d_name);
- if (fd < 3)
- continue;
-
- if (fd == dirfd(dp) || fd == aul_fd)
- continue;
-
- close(fd);
- }
- closedir(dp);
-
- return 0;
-}
-
-static int __redirect_stdin(void)
-{
- int ret;
- int fd;
-
- fd = open(PATH_DEV_NULL, O_RDONLY | O_NOCTTY);
- if (fd < 0) {
- ret = -errno;
- _E("open(%s) is failed. errno(%d)", PATH_DEV_NULL, errno);
- return ret;
- }
-
- ret = dup2(fd, STDIN_FILENO);
- if (ret < 0)
- _W("dup2(%d, 0) is failed. errno(%d)", fd, errno);
-
- close(fd);
- return ret;
-}
-
-static int __redirect_stdout(const char *ident)
-{
- int ret;
- int fd;
-
- ret = dlog_connect_fd(LOG_ID_APPS, STDOUT_FILENO, "STDOUT", DLOG_WARN);
- if (ret == 0) {
- _W("STDOUT_FILENO redirection is successful");
- return 0;
- }
-
- fd = sd_journal_stream_fd(ident, LOG_INFO, 0);
- if (fd < 0) {
- if (fd != -ENOENT)
- _W("sd_journal_stream_fd() is failed. error(%d)", fd);
- fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY);
- if (fd < 0) {
- ret = -errno;
- _E("open(%s) is failed. errno(%d)",
- PATH_DEV_NULL, errno);
- close(STDOUT_FILENO);
- return ret;
- }
- }
-
- ret = dup2(fd, STDOUT_FILENO);
- if (ret < 0) {
- ret = -errno;
- _E("dup(%d, 1) is failed. errno(%d)", fd, errno);
- close(STDOUT_FILENO);
- }
-
- close(fd);
- return ret;
-}
-
-static int __redirect_stderr(const char *ident)
-{
- int ret;
- int fd;
-
- ret = dlog_connect_fd(LOG_ID_APPS, STDERR_FILENO, "STDERR", DLOG_ERROR);
- if (ret == 0) {
- _W("STDERR_FILENO redirection is successful");
- return 0;
- }
-
- fd = sd_journal_stream_fd(ident, LOG_WARNING, 0);
- if (fd < 0) {
- if (fd != -ENOENT)
- _W("sd_journal_stream_fd() is failed. error(%d)", fd);
- fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY);
- if (fd < 0) {
- ret = -errno;
- _E("open(%s) is failed. errno(%d)",
- PATH_DEV_NULL, errno);
- close(STDERR_FILENO);
- return ret;
- }
- }
-
- ret = dup2(fd, STDERR_FILENO);
- if (ret < 0) {
- ret = -errno;
- _E("dup(%d, 2) is failed. errno(%d)", fd, errno);
- close(STDERR_FILENO);
- }
-
- close(fd);
- return ret;
-
-}
-
-int _setup_stdio(const char *ident)
-{
- int ret;
-
- ret = __redirect_stdin();
- if (ret < 0)
- return ret;
-
- ret = __redirect_stdout(ident);
- if (ret < 0)
- return ret;
-
- ret = __redirect_stderr(ident);
- if (ret < 0)
- return ret;
-
- return 0;
-}
-
-int _set_priority(int prio)
-{
- int ret;
-
- ret = setpriority(PRIO_PGRP, 0, prio);
- if (ret != 0) {
- SECURE_LOGE("Failed to set process(%d) priority(%d) - err(%d)",
- getpid(), prio, errno);
- } else {
- SECURE_LOGD("priority(%d)", prio);
- }
-
- return ret;
-}
-
-static int __dbus_send_message(DBusMessage *callback(void *), void *user_data,
- int timeout, int *result)
-{
- DBusError err;
- DBusConnection *conn;
- DBusMessage *msg = NULL;
- DBusMessageIter args;
- DBusPendingCall *pending = NULL;
- dbus_bool_t r;
- dbus_int32_t i;
- int ret = 0;
-
- dbus_error_init(&err);
- conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
- if (!conn) {
- _E("Failed to connect to D-Bus Daemon");
- ret = -1;
- goto end;
- }
-
- msg = callback(user_data);
- if (!msg) {
- _E("Message is nullptr");
- goto end;
- }
-
- r = dbus_connection_send_with_reply(conn, msg, &pending, timeout);
- if (!r || !pending) {
- _E("Failed to send message");
- ret = -1;
- goto end;
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(msg);
-
- dbus_pending_call_block(pending);
- msg = dbus_pending_call_steal_reply(pending);
- if (!msg) {
- _E("Failed to get reply message");
- ret = -1;
- goto end;
- }
-
- dbus_pending_call_unref(pending);
-
- if (!dbus_message_iter_init(msg, &args)) {
- _E("Message has no arguments!");
- ret = -1;
- } else if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_INT32) {
- _E("Argument is not integer! type(%d)",
- dbus_message_iter_get_arg_type(&args));
- ret = -1;
- } else {
- dbus_message_iter_get_basic(&args, &i);
- *result = i;
- }
-
- _D("Result: %d", *result);
-end:
- if (msg)
- dbus_message_unref(msg);
-
- if (conn)
- dbus_connection_close(conn);
-
- if (dbus_error_is_set(&err)) {
- _E("D-Bus error(%s)", err.message);
- dbus_error_free(&err);
- }
-
- return ret;
-}
-
-static DBusMessage *__create_tep_mount_message(void *user_data)
-{
- DBusMessage *message;
- DBusMessageIter args;
- dbus_bool_t r;
- const char *tep_path = (const char *)user_data;
-
- message = dbus_message_new_method_call(TEP_BUS_NAME,
- TEP_OBJECT_PATH,
- TEP_INTERFACE_NAME,
- TEP_IS_MOUNTED_METHOD);
- if (!message) {
- _E("Message is nullptr");
- return NULL;
- }
-
- dbus_message_iter_init_append(message, &args);
- r = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &tep_path);
- if (!r) {
- _E("Out of memory");
- dbus_message_unref(message);
- return NULL;
- }
-
- return message;
-}
-
-static int __is_tep_mount_done(const char *tep_path)
-{
- int result = -1;
- int ret;
-
- ret = __dbus_send_message(__create_tep_mount_message,
- (void *)tep_path, 500, &result);
- if (ret != 0)
- _E("Failed to send message");
-
- return result;
-}
-
-static int __check_tep_mount(const char *tep_path)
-{
- int r;
- int cnt = 0;
-
- if (!tep_path)
- return 0;
-
- while (cnt < MAX_TEP_IS_MOUNT_RETRY_CNT) {
- r = __is_tep_mount_done(tep_path);
- if (r == 1)
- break;
- usleep(50 * 1000);
- cnt++;
- }
-
- if (r != 1) {
- _E("Not able to mount within 5 sec: %s", tep_path);
- return -1;
- }
-
- return 0;
-}
-
-int _wait_tep_mount(bundle *b)
-{
- int r;
- int i;
- int len = 0;
- const char **tep_paths;
-
- tep_paths = bundle_get_str_array(b, AUL_K_TEP_PATH, &len);
- if (!tep_paths)
- return 0;
-
- for (i = 0; i < len; ++i) {
- r = __check_tep_mount(tep_paths[i]);
- if (r < 0)
- return -1;
- }
-
- _I("Mount has been done.");
- return 0;
-}
-
-static int __create_app_socket(int pid, uid_t uid)
-{
- int fd;
- char path[PATH_MAX];
- struct sockaddr_un addr = {
- .sun_family = AF_UNIX,
- };
-
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
- if (fd < 0) {
- if (errno == EINVAL) {
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) {
- _E("Second chance - socket create errno(%d)",
- errno);
- return -1;
- }
- } else {
- _E("Failed to create socket. errno(%d)", errno);
- return -1;
- }
- }
-
- snprintf(path, sizeof(path), "/run/aul/apps/%u/%d", uid, pid);
- if (mkdir(path, 0700) != 0) {
- if (errno == EEXIST) {
- if (access(path, R_OK) != 0) {
- _E("Failed to access %s. errno(%d)",
- path, errno);
- close(fd);
- return -errno;
- }
- } else {
- _E("Failed to access %s. errno(%d)", path, errno);
- close(fd);
- return -1;
- }
- }
-
- snprintf(addr.sun_path, sizeof(addr.sun_path),
- "/run/aul/apps/%u/%d/.app-sock", uid, pid);
- unlink(addr.sun_path);
-
- if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- _E("Failed to bind socket(%d), errno(%d)", fd, errno);
- close(fd);
- return -1;
- }
-
- if (_set_sock_option(fd, 0) < 0) {
- _E("Failed to set sock option");
- close(fd);
- return -1;
- }
-
- if (listen(fd, 128) < 0) {
- _E("Failed to listen %d, errno(%d)", fd, errno);
- close(fd);
- return -1;
- }
-
- return fd;
-}
-
-int _prepare_app_socket(void)
-{
- int fd;
- char buf[12];
-
- fd = __create_app_socket(getpid(), getuid());
- if (fd < 0)
- return fd;
-
- snprintf(buf, sizeof(buf), "%d", fd);
- setenv("AUL_LISTEN_FD", buf, 1);
-
- return 0;
-}
-
-struct package_info_s {
- const char *id;
- uid_t uid;
-};
-
-static DBusMessage *__create_app2sd_message(void *user_data)
-{
- struct package_info_s *pkg_info = (struct package_info_s *)user_data;
- DBusMessage *message;
- DBusMessageIter args;
- dbus_bool_t r;
-
- _D("[__APP2SD__] package(%s), uid(%u)", pkg_info->id, pkg_info->uid);
-
- message = dbus_message_new_method_call(APP2SD_BUS_NAME,
- APP2SD_OBJECT_PATH,
- APP2SD_INTERFACE_NAME,
- APP2SD_ONDEMANDSETUPINIT_METHOD);
- if (!message) {
- _E("Message is nullptr");
- return NULL;
- }
-
- dbus_message_iter_init_append(message, &args);
- r = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
- &pkg_info->id);
- if (!r) {
- _E("Failed to append pkgid");
- dbus_message_unref(message);
- return NULL;
- }
-
- r = dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32,
- &pkg_info->uid);
- if (!r) {
- _E("Failed to append uid");
- dbus_message_unref(message);
- return NULL;
- }
-
- return message;
-}
-
-int _enable_external_pkg(bundle *b, const char *pkgid, uid_t pkg_uid)
-{
- const char *installed_storage;
- int retry_cnt = 0;
- int result = -1;
- int ret;
- struct package_info_s pkg_info = {
- .id = pkgid,
- .uid = pkg_uid
- };
-
- installed_storage = bundle_get_val(b, AUL_K_INSTALLED_STORAGE);
- if (!installed_storage || strcmp(installed_storage, "external") != 0)
- return 0;
-
- do {
- ret = __dbus_send_message(__create_app2sd_message,
- &pkg_info, 500, &result);
- if (ret != 0) {
- _E("Failed to send message");
- retry_cnt++;
- usleep(APP2SD_WAIT_USEC);
- continue;
- }
-
- break;
- } while (retry_cnt <= APP2SD_RETRY_MAX);
-
- _D("[__APP2SD__] result(%d)", result);
-
- return result;
-}
-
-int _verify_proc_caps(void)
-{
- cap_t cap_d;
- cap_flag_value_t eff_state;
- cap_flag_value_t inh_state;
- cap_value_t value = CAP_SETGID;
- int r;
-
- cap_d = cap_get_proc();
- if (!cap_d) {
- _E("Failed to get cap from proc. pid(%d)", getpid());
- return -1;
- }
-
- r = cap_get_flag(cap_d, value, CAP_INHERITABLE, &inh_state);
- if (r != 0) {
- _E("Failed to get cap inh - errno(%d)", errno);
- cap_free(cap_d);
- return -1;
- }
-
- r = cap_get_flag(cap_d, value, CAP_EFFECTIVE, &eff_state);
- if (r != 0) {
- _E("Failed to get cap eff - errno(%d)", errno);
- cap_free(cap_d);
- return -1;
- }
-
- if ((inh_state != CAP_SET) || (eff_state != CAP_SET)) {
- _E("The process(%d) doesn't have %d cap",
- getpid(), value);
- cap_free(cap_d);
- return -1;
- }
- cap_free(cap_d);
-
- return 0;
-}
-
-int _prepare_id_file(void)
-{
- char path[PATH_MAX];
- int fd;
-
- snprintf(path, sizeof(path), "/run/aul/apps/%u/%d/%s",
- getuid(), getpid(), getenv("AUL_APPID"));
- fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0600);
- if (fd < 0) {
- _E("Failed to create %s. errno(%d)", path, errno);
- return -1;
- }
- close(fd);
-
- return 0;
-}
-
-void _print_hwc_log(const char *format, ...)
-{
- char buf[1024];
- va_list ap;
- int ret;
-
- va_start(ap, format);
- ret = vsnprintf(buf, sizeof(buf), format, ap);
- va_end(ap);
- if (ret < 0 || ret >= sizeof(buf)) {
- _E("vsnprintf() is failed. result(%d)", ret);
- return;
- }
-
- prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf));
-}
-
-static int __get_mount_opt(const char *srcs[], size_t srcs_len,
- const char *dest, char *opt, size_t opt_len)
-{
- size_t i;
- char buf[PATH_MAX];
- int ret;
-
- /* read-only mount (without upperdir,workdir) needs at least 2 lowerdir,
- * so we set dest itself as lowerdir.
- */
- snprintf(opt, opt_len, "lowerdir=%s", dest);
- for (i = 0; i < srcs_len; i++) {
- ret = snprintf(buf, sizeof(buf), "%s:%s", opt, srcs[i]);
- if (ret < 0) {
- _E("source directory string size is too large");
- return -1;
- }
- snprintf(opt, opt_len, "%s", buf);
- }
-
- _D("mount opt: %s", opt);
-
- return 0;
-}
-
-static int __mount_dir(const char *srcs[], size_t srcs_len, const char *dest)
-{
- int ret;
- char opt[PATH_MAX];
-
- ret = __get_mount_opt(srcs, srcs_len, dest, opt, sizeof(opt));
- if (ret < 0) {
- _E("Failed to get mount option");
- return -1;
- }
-
- ret = mount(NULL, dest, "overlay", MS_RDONLY, opt);
- if (ret < 0) {
- _E("Failed to mount dir %s. errno(%d)", dest, errno);
- return -1;
- }
-
- return 0;
-}
-
-static void __set_mount_pkgids_to_env(const char *pkgids[], size_t len)
-{
- int i;
- char val[PATH_MAX] = { 0 };
-
- for (i = 0; i < len; i++)
- snprintf(val + strlen(val), sizeof(val) - strlen(val), "%s:",
- pkgids[i]);
-
- val[strlen(val) - 1] = '\0';
-
- /* RES_PKGIDS=org.tizen.res1:org.tizen.res2:org.tizen.res3 */
- setenv("RES_PKGIDS", val, 1);
-}
-
-int _mount_res_dir(const char *root_path, bundle *kb)
-{
- const char **val;
- int len;
- char dest[PATH_MAX];
-
- val = bundle_get_str_array(kb, AUL_K_MOUNT_GLOBAL_RES_DIR, &len);
- if (val) {
- snprintf(dest, sizeof(dest), "%s/res/mount/global", root_path);
- __mount_dir(val, len, dest);
- } else if (get_last_result() != BUNDLE_ERROR_KEY_NOT_AVAILABLE) {
- _E("invalid mount info");
- return -1;
- }
-
- val = bundle_get_str_array(kb, AUL_K_MOUNT_ALLOWED_RES_DIR, &len);
- if (val) {
- snprintf(dest, sizeof(dest), "%s/res/mount/allowed", root_path);
- __mount_dir(val, len, dest);
- } else if (get_last_result() != BUNDLE_ERROR_KEY_NOT_AVAILABLE) {
- _E("invalid mount info");
- return -1;
- }
-
- val = bundle_get_str_array(kb, AUL_K_MOUNT_RES_PKGIDS, &len);
- if (val) {
- __set_mount_pkgids_to_env(val, len);
- } else if (get_last_result() != BUNDLE_ERROR_KEY_NOT_AVAILABLE) {
- _E("invalid mount info");
- return -1;
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <dlfcn.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "launchpad_plugin.h"
-#include "log_private.h"
-
-#define PATH_LAUNCHPAD_PLUGIN "/usr/share/aul/plugin/liblaunchpad-plugin.so"
-#define TAG_LAUNCHPAD_PLUGIN_PREPARE_APP "LAUNCHPAD_PLUGIN_PREPARE_APP"
-
-int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb)
-{
- void *handle;
- int (*prepare_app)(const char *, bundle *);
- int ret;
-
- ret = access(PATH_LAUNCHPAD_PLUGIN, F_OK);
- if (ret != 0) {
- if (errno != ENOENT)
- _W("plugin module does not exist. errno(%d)", errno);
- return 0;
- }
-
- handle = dlopen(PATH_LAUNCHPAD_PLUGIN, RTLD_LAZY | RTLD_LOCAL);
- if (!handle) {
- _W("Failed to open plugin so. error(%s)", dlerror());
- return 0;
- }
-
- prepare_app = dlsym(handle, TAG_LAUNCHPAD_PLUGIN_PREPARE_APP);
- if (!prepare_app) {
- _W("Failed to load %s", TAG_LAUNCHPAD_PLUGIN_PREPARE_APP);
- dlclose(handle);
- return 0;
- }
-
- _W("LAUNCHPAD_PLUGIN_PREPARE_APP ++");
- ret = prepare_app(app_id, kb);
- _W("LAUNCHPAD_PLUGIN_PREPARE_APP --");
- if (ret != 0)
- return -1;
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <linux/limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "launchpad_proc.h"
-#include "log_private.h"
-
-#define auto_ptr(x) __attribute__ ((__cleanup__(x)))
-
-static unsigned int __convert_string(const char *str)
-{
- while (*str < '0' || *str > '9')
- str++;
-
- return atoi(str);
-}
-
-static int __open_file(const char *file, FILE **fp)
-{
- int ret;
-
- *fp = fopen(file, "r");
- if (!*fp) {
- ret = -errno;
- _E("Failed to open %s. errno(%d)", file, errno);
- return ret;
- }
-
- return 0;
-}
-
-static void __close_file(FILE **fp)
-{
- if (!fp || !*fp)
- return;
-
- fclose(*fp);
-}
-
-int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio)
-{
- auto_ptr(__close_file) FILE *fp = NULL;
- char buf[LINE_MAX];
- char *str;
- unsigned int mem_free = 0;
- unsigned int mem_total = 0;
- unsigned int mem_available = 0;
- unsigned int cached = 0;
- unsigned int used;
- unsigned int used_ratio;
- int ret;
-
- if (!mem_used_ratio) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- ret = __open_file("/proc/meminfo", &fp);
- if (ret != 0)
- return ret;
-
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if ((str = strstr(buf, "MemTotal:"))) {
- str += strlen("MemTotal:");
- mem_total = __convert_string(str);
- } else if ((str = strstr(buf, "MemFree:"))) {
- str += strlen("MemFree:");
- mem_free = __convert_string(str);
- } else if ((str = strstr(buf, "MemAvailable:"))) {
- str += strlen("MemAvailable:");
- mem_available = __convert_string(str);
- } else if ((str = strstr(buf, "Cached:")) &&
- !strstr(buf, "Swap")) {
- str += strlen("Cached:");
- cached = atoi(str);
- break;
- }
- }
-
- if (mem_total == 0) {
- _E("Failed to get total memory size");
- return -1;
- }
-
- if (mem_available == 0)
- mem_available = mem_free + cached;
-
- used = mem_total - mem_available;
- used_ratio = used * 100 / mem_total;
-
- *mem_used_ratio = used_ratio;
-
- return 0;
-}
-
-int _proc_get_mem_pss(int pid, unsigned int *mem_pss)
-{
- auto_ptr(__close_file) FILE *fp = NULL;
- char path[PATH_MAX];
- char buf[LINE_MAX];
- unsigned int pss = 0;
- unsigned int total_pss = 0;
- int ret;
-
- if (pid < 1 || !mem_pss) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- snprintf(path, sizeof(path), "/proc/%d/smaps", pid);
- ret = __open_file(path, &fp);
- if (ret != 0)
- return ret;
-
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (sscanf(buf, "Pss: %d kB", &pss) == 1) {
- total_pss += pss;
- pss = 0;
- }
- }
-
- *mem_pss = total_pss;
-
- return 0;
-}
-
-static void __close_fd(int *fd)
-{
- if (!fd)
- return;
-
- if (*fd < 0)
- return;
-
- close(*fd);
-}
-
-int _proc_get_attr(int pid, void *buf, unsigned int size)
-{
- auto_ptr(__close_fd) int fd = -1;
- char path[PATH_MAX];
- char *buffer = buf;
- int ret;
-
- if (pid < 1 || !buf || !size) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- snprintf(path, sizeof(path), "/proc/%d/attr/current", pid);
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- ret = -errno;
- _E("open() is failed. errno(%d)", errno);
- return ret;
- }
-
- ret = read(fd, buffer, size - 1);
- if (ret < 0) {
- ret = -errno;
- _E("read() is failed. fd(%d), errno(%d)", fd, errno);
- return ret;
- }
-
- buffer[ret] = 0;
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-#include "launchpad_socket.h"
-#include "log_private.h"
-
-#define LAUNCHPAD_SOCKET_MAX_BUFF 131071
-#define LAUNCHPAD_SOCKET_RETRY_TIME (100 * 1000)
-#define LAUNCHPAD_SOCKET_RETRY_COUNT 3
-#define LAUNCHPAD_SOCKET_MAX_PENDING_CONNECTION 128
-
-struct socket_s {
- char *path;
- bool client;
- int fd;
- int pid;
-};
-
-static int __set_socket_option(int fd, bool client)
-{
- struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */
- int size = LAUNCHPAD_SOCKET_MAX_BUFF;
- int flag;
- int ret;
-
- ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt(SO_SNDBUF) is failed. fd(%d), errno(%d)",
- fd, errno);
- return ret;
- }
-
- ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt(SO_RCVBUF) is failed. fd(%d), errno(%d)",
- fd, errno);
- return ret;
- }
-
- if (!client)
- return 0;
-
- ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt(SO_RCVTIMEO) is failed. fd(%d), errno(%d)",
- fd, errno);
- return ret;
- }
-
- flag = fcntl(fd, F_GETFD);
- flag |= FD_CLOEXEC;
- ret = fcntl(fd, F_SETFD, flag);
- if (ret < 0) {
- ret = -errno;
- _E("fcntl(F_SETFD) is failed. fd(%d), errno(%d)", fd, errno);
- return ret;
- }
-
- return 0;
-}
-
-static int __create_server_socket(const char *path)
-{
- struct sockaddr_un addr = { 0, };
- int ret;
- int fd;
-
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd < 0) {
- ret = -errno;
- _E("socket() is failed. path(%s), errno(%d)", path, errno);
- return ret;
- }
-
- addr.sun_family = AF_UNIX;
- snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
- unlink(addr.sun_path);
-
- ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
- if (ret < 0) {
- ret = -errno;
- _E("bind() is failed. path(%s), errno(%d)", path, errno);
- close(fd);
- return ret;
- }
-
- ret = __set_socket_option(fd, false);
- if (ret < 0) {
- close(fd);
- return ret;
- }
-
- ret = listen(fd, LAUNCHPAD_SOCKET_MAX_PENDING_CONNECTION);
- if (ret < 0) {
- ret = -errno;
- _E("listen() is failed. path(%s), errno(%d)", path, errno);
- close(fd);
- return ret;
- }
-
- return fd;
-}
-
-static int __create_client_socket(const char *path)
-{
- struct sockaddr_un addr = { 0, };
- int retry = LAUNCHPAD_SOCKET_RETRY_COUNT;
- int ret;
- int fd;
-
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd < 0) {
- ret = -errno;
- _E("socket() is failed. path(%s), errno(%d)", path, errno);
- return ret;
- }
-
- addr.sun_family = AF_UNIX;
- snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
- while (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- if (errno != ETIMEDOUT || retry <= 0) {
- ret = -errno;
- _E("connect() is failed. path(%s), errno(%d)",
- path, errno);
- close(fd);
- return ret;
- }
-
- usleep(LAUNCHPAD_SOCKET_RETRY_TIME);
- retry--;
- _W("Retry(%d) to connect to %s", retry, path);
- }
-
- ret = __set_socket_option(fd, true);
- if (ret < 0) {
- close(fd);
- return ret;
- }
-
- return fd;
-}
-
-static void __destroy_socket(struct socket_s *sock)
-{
- if (!sock)
- return;
-
- if (!sock->client && sock->fd > 0 && sock->path)
- unlink(sock->path);
-
- free(sock->path);
- free(sock);
-}
-
-static struct socket_s *__create_socket(const char *path, bool client,
- int fd, int pid)
-{
- struct socket_s *sock;
-
- sock = calloc(1, sizeof(struct socket_s));
- if (!sock) {
- _E("Out of memory");
- return NULL;
- }
-
- if (path) {
- sock->path = strdup(path);
- if (!sock->path) {
- _E("Failed to duplicate socket path(%s)", path);
- __destroy_socket(sock);
- return NULL;
- }
- }
-
- sock->client = client;
- sock->fd = fd;
- sock->pid = pid;
-
- return sock;
-}
-
-int _socket_create(const char *path, bool client, socket_h *handle)
-{
- struct socket_s *sock;
- int fd;
-
- if (!path || !handle) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- if (client)
- fd = __create_client_socket(path);
- else
- fd = __create_server_socket(path);
-
- if (fd < 0)
- return fd;
-
- sock = __create_socket(path, client, fd, getpid());
- if (!sock) {
- close(fd);
- return -ENOMEM;
- }
-
- *handle = sock;
-
- return 0;
-}
-
-int _socket_create_with_fd(int fd, socket_h *handle)
-{
- struct socket_s *sock;
-
- if (fd < 0 || !handle) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- sock = __create_socket(NULL, true, fd, getpid());
- if (!sock)
- return -ENOMEM;
-
- *handle = sock;
-
- return 0;
-}
-
-int _socket_destroy(socket_h handle)
-{
- if (!handle) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- if (handle->fd > 0)
- close(handle->fd);
-
- __destroy_socket(handle);
-
- return 0;
-}
-
-int _socket_accept(socket_h handle, socket_h *client_socket)
-{
- struct socket_s *sock;
- struct sockaddr_un addr = { 0, };
- struct ucred cred = { 0, };
- socklen_t addr_size = (socklen_t)sizeof(struct sockaddr_un);
- socklen_t cred_size = (socklen_t)sizeof(struct ucred);
- int client_fd;
- int ret;
-
- if (!handle || !client_socket) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- client_fd = accept(handle->fd, (struct sockaddr *)&addr, &addr_size);
- if (client_fd < 0) {
- ret = -errno;
- _E("accept() is failed. errno(%d)", errno);
- return ret;
- }
-
- ret = getsockopt(client_fd, SOL_SOCKET, SO_PEERCRED, &cred, &cred_size);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt(SO_PEERCRED) is failed. errno(%d)", errno);
- close(client_fd);
- return ret;
- }
-
- ret = __set_socket_option(client_fd, true);
- if (ret < 0) {
- close(client_fd);
- return ret;
- }
-
- sock = __create_socket(NULL, true, client_fd, cred.pid);
- if (!sock) {
- close(client_fd);
- return -ENOMEM;
- }
-
- *client_socket = sock;
-
- return 0;
-}
-
-int _socket_get_fd(socket_h handle, int *fd)
-{
- if (!handle || !fd) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- *fd = handle->fd;
-
- return 0;
-}
-
-int _socket_set_fd(socket_h handle, int fd)
-{
- if (!handle) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- handle->fd = fd;
-
- return 0;
-}
-
-int _socket_get_pid(socket_h handle, int *pid)
-{
- if (!handle || !pid) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- *pid = handle->pid;
-
- return 0;
-}
-
-int _socket_send(socket_h handle, const void *buf, unsigned int size)
-{
- unsigned char *buffer = (unsigned char *)buf;
- unsigned int left = size;
- ssize_t write_size;
- int ret;
-
- if (!handle || !buf || !size) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- while (left) {
- write_size = send(handle->fd, buffer, left, MSG_NOSIGNAL);
- if (write_size < 0) {
- ret = -errno;
- _E("send() is failed. fd(%d), errno(%d)",
- handle->fd, errno);
- return ret;
- }
-
- left -= write_size;
- buffer += write_size;
- }
-
- return 0;
-}
-
-int _socket_read(socket_h handle, void *buf, unsigned int size)
-{
- unsigned char *buffer = (unsigned char *)buf;
- unsigned int left = size;
- ssize_t read_size;
-
- if (!handle || !buf || !size) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- while (left) {
- read_size = read(handle->fd, buffer, left);
- if (read_size == 0) {
- _W("EOF. fd(%d)", handle->fd);
- return -EIO;
- } else if (read_size < 0) {
- return -errno;
- }
-
- left -= read_size;
- buffer += read_size;
- }
-
- return 0;
-}