From 3f3d13b9189361f9cee636ecfa354cf56bb65e82 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 26 Jul 2023 15:12:47 +0900 Subject: [PATCH 01/16] Handle loader termination request Some developers want to send the kill request to the running loader process. This patch adds a new handler to handle the kill request. Change-Id: Iad92282db51f60a8bb420739f406e1a426bb203e Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 19 +++++++++++++++++++ src/launchpad-process-pool/launchpad.hh | 1 + src/launchpad-process-pool/loader_manager.hh | 4 ++-- src/lib/launchpad-common/types.hh | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 1ffb1ec..69ddf1a 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -191,6 +191,9 @@ Launchpad::Launchpad(int argc, char** argv) { PadCmd::Launch, std::bind(&Launchpad::HandleLaunchRequest, this, std::placeholders::_1) }, + { PadCmd::KillLoader, + std::bind(&Launchpad::HandleKillLoaderRequest, this, + std::placeholders::_1) }, }; CPUBoostController::DoBoost(getpid(), CPUBoostController::Level::Strong, @@ -558,6 +561,22 @@ void Launchpad::HandleLaunchRequest(std::shared_ptr request) { request->GetAppInfo()->GetAppId().c_str(), request->GetPid()); } +void Launchpad::HandleKillLoaderRequest(std::shared_ptr request) { + auto& b = request->GetBundle(); + auto loader_name = b.GetString(kAulLoaderName); + auto loader_context = + LoaderManager::GetInst().FindLoaderContextFromName(loader_name); + if (loader_context == nullptr) { + _E("Failed to find loader context. loader_name(%s)", loader_name.c_str()); + return; + } + + if (loader_context->RefCount() == 0) + loader_context->Dispose(); + + _D("[PAD_CMD_KILL_LOADER] loader_name: %s", loader_name.c_str()); +} + void Launchpad::OnIOEventReceived(int fd, int condition) { auto client_socket = socket_->Accept(); if (!client_socket) { diff --git a/src/launchpad-process-pool/launchpad.hh b/src/launchpad-process-pool/launchpad.hh index 5300f31..b287375 100644 --- a/src/launchpad-process-pool/launchpad.hh +++ b/src/launchpad-process-pool/launchpad.hh @@ -76,6 +76,7 @@ class Launchpad : public IOChannel::IEvent, void HandleUpdateAppTypeRequest(std::shared_ptr request); void HandleConnectRequest(std::shared_ptr request); void HandleLaunchRequest(std::shared_ptr request); + void HandleKillLoaderRequest(std::shared_ptr request); bool CanUseLoaderContext(const std::shared_ptr& context); LaunchResult ForkProcessing(std::shared_ptr request); diff --git a/src/launchpad-process-pool/loader_manager.hh b/src/launchpad-process-pool/loader_manager.hh index 31e4ba0..76825ad 100644 --- a/src/launchpad-process-pool/loader_manager.hh +++ b/src/launchpad-process-pool/loader_manager.hh @@ -76,6 +76,8 @@ class LoaderManager : public AppDefinedLoaderInfoManager::IEvent, const std::string& loader_name); std::shared_ptr FindAlternativeLoaderContext(LoaderType type); void RemoveLoaderContext(LoaderType type, int loader_id); + std::shared_ptr FindLoaderContextFromName( + const std::string& loader_name); private: LoaderManager(); @@ -84,8 +86,6 @@ class LoaderManager : public AppDefinedLoaderInfoManager::IEvent, void Init(); std::shared_ptr FindLoaderContextFromPid(pid_t pid); std::shared_ptr FindHydraLoaderContextFromPid(pid_t pid); - std::shared_ptr FindLoaderContextFromName( - const std::string& loader_name); std::shared_ptr FindLoaderContextFromLoaderId(int loader_id); std::shared_ptr FindLoaderContextFromType(LoaderType type); void RemoveLoaderContextsByCallerPid(pid_t caller_pid); diff --git a/src/lib/launchpad-common/types.hh b/src/lib/launchpad-common/types.hh index e19b5b3..dca55f4 100644 --- a/src/lib/launchpad-common/types.hh +++ b/src/lib/launchpad-common/types.hh @@ -57,6 +57,7 @@ enum PadCmd { UpdateAppType = 16, PrepareAppDefinedLoader = 17, Connect = 18, + KillLoader = 19, }; enum PadLoaderId { -- 2.7.4 From 45d28573d27cae75c4a6dec477ca3adc79974cec Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 27 Jul 2023 11:13:12 +0900 Subject: [PATCH 02/16] Release version 0.36.0 Changes: - Handle loader termination request Change-Id: I0a4d6fd7ee908bde5fc79e08604a0f0aa2718d82 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index cb7c8a8..4960f77 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.35.18 +Version: 0.36.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 258cc771f70c128907f3646233c22fd6c3d1970e Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Fri, 28 Jul 2023 10:54:38 +0900 Subject: [PATCH 03/16] Fix static analysis issues Changes: - Changes method to stoull. Change-Id: I802be7a7e343b219f1cded40ec9560c2886ee129 Signed-off-by: Changgyu Choi --- src/app-defined-loader/app-defined-loader.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app-defined-loader/app-defined-loader.cc b/src/app-defined-loader/app-defined-loader.cc index 01e73e0..57e7ffd 100644 --- a/src/app-defined-loader/app-defined-loader.cc +++ b/src/app-defined-loader/app-defined-loader.cc @@ -68,7 +68,7 @@ class AppDefinedLoader { IniParser parser(PATH_CONF); auto value = parser.Get(SECTION_MEMORY, KEY_THRESHOLD); if (!value.empty()) - threshold_ = static_cast(std::stoi(value)); + threshold_ = static_cast(std::stoull(value)); else _W("Failed to get threshold"); } -- 2.7.4 From e87cb3348b6b11235e024dd963655940a7d39e10 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Fri, 28 Jul 2023 13:33:59 +0900 Subject: [PATCH 04/16] Release version 0.36.1 Changes: - Fix static analysis issues Change-Id: I77826afded881cf7c7f5dde783905f1525fd2a0f Signed-off-by: Changgyu Choi --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 4960f77..e1dc46d 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.36.0 +Version: 0.36.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From c15be5f3584066fc2a2095508f134d6840afff74 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 1 Aug 2023 12:15:33 +0900 Subject: [PATCH 05/16] Change multiple instance appid key Change-Id: I6586c84e52ee060dc64283eac23eefe96f2604e5 Signed-off-by: Changgyu Choi --- src/lib/launchpad-common/aul_keys.hh | 2 +- src/lib/launchpad-glib/util.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/launchpad-common/aul_keys.hh b/src/lib/launchpad-common/aul_keys.hh index 6b478f1..4a4cc70 100644 --- a/src/lib/launchpad-common/aul_keys.hh +++ b/src/lib/launchpad-common/aul_keys.hh @@ -51,7 +51,7 @@ constexpr const char kAulMountGlobalResDir[] = "__AUL_MOUNT_GLOBAL_RES_DIR__"; constexpr const char kAulMountAllowedResDir[] = "__AUL_MOUNT_ALLOWED_RES_DIR__"; constexpr const char kAulEnabledLightUser[] = "__AUL_ENABLED_LIGHT_USER__"; constexpr const char kAulMountResPkgIds[] = "__AUL_MOUNT_RES_PKGIDS__"; -constexpr const char kAulOrgAppId[] = "__AUL_ORG_APPID__"; +constexpr const char kAulMultipleInstanceAppId[] = "__AUL_MULTIPLE_INSTANCE_APPID__"; } // namespace launchpad diff --git a/src/lib/launchpad-glib/util.cc b/src/lib/launchpad-glib/util.cc index 08b6518..9ab6d9e 100644 --- a/src/lib/launchpad-glib/util.cc +++ b/src/lib/launchpad-glib/util.cc @@ -343,9 +343,9 @@ void Util::SetEnvironments(const AppInfo* app_info) { setenv("AUL_ROOT_PATH", app_info->GetRootPath().c_str(), 1); if (!app_info->GetAppId().empty()) { - auto org_app_id = b.GetString(kAulOrgAppId); - if (!org_app_id.empty()) - setenv("AUL_APPID", org_app_id.c_str(), 1); + auto multiple_instance_app_id = b.GetString(kAulMultipleInstanceAppId); + if (!multiple_instance_app_id.empty()) + setenv("AUL_APPID", multiple_instance_app_id.c_str(), 1); else setenv("AUL_APPID", app_info->GetAppId().c_str(), 1); } -- 2.7.4 From 6bf84c120d360b0ee7080c1d9aafadc19bffe2ab Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 1 Aug 2023 13:46:02 +0900 Subject: [PATCH 06/16] Release version 0.36.2 Changes: - Change multiple instance appid key Change-Id: I1fbc64259cd2b8db342d6c1b75be011709d7eb2c Signed-off-by: Changgyu Choi --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index e1dc46d..e21611d 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.36.1 +Version: 0.36.2 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 2e19fffa4052578b1127951c12caaab007c1a122 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 11 Aug 2023 12:31:50 +0900 Subject: [PATCH 07/16] Add a missing exception handling The Vconf::Get can throw an exception. This patch adds an exception handling to prevent a crash issue. Change-Id: I96943d2e02b898bf07881d6327f303a923d4a2f7 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/memory_monitor.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/launchpad-process-pool/memory_monitor.cc b/src/launchpad-process-pool/memory_monitor.cc index ee6667f..d92de1f 100644 --- a/src/launchpad-process-pool/memory_monitor.cc +++ b/src/launchpad-process-pool/memory_monitor.cc @@ -63,9 +63,13 @@ void MemoryMonitor::SetEventListener(MemoryMonitor::IEvent* listener) { } bool MemoryMonitor::IsLowMemory() { - if (low_vconf_.Get() >= - Config::GetInst().GetMemoryStatus().GetLowValue()) - return true; + try { + if (low_vconf_.Get() >= + Config::GetInst().GetMemoryStatus().GetLowValue()) + return true; + } catch (const Exception& e) { + _E("Exception occurs. error(%s)", e.what()); + } if (threshold_ == 100) return false; -- 2.7.4 From 72f8ca9f6ff4ee53e382c73bac1eaba6e2c01022 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 11 Aug 2023 15:26:58 +0900 Subject: [PATCH 08/16] Close all fds while creating process pool After calling fork(), the child process should close all unused file descriptors. Change-Id: I5c0e714dff3bff182fdafbeb1153da5b4e38d0b7 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 1 + src/launchpad-process-pool/loader_manager.cc | 7 +++++++ src/launchpad-process-pool/process_pool.cc | 4 ++++ src/lib/launchpad-glib/util.cc | 10 +++++++++- src/lib/launchpad-glib/util.hh | 3 ++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 69ddf1a..bc51ef5 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -497,6 +497,7 @@ Launchpad::LaunchResult Launchpad::LaunchRequestPend( if (loader_context->GetPid() > 0) { CPUBoostController::DoBoost(loader_context->GetPid(), CPUBoostController::Level::Strong, 10000); + _W("Send result: %d", loader_context->GetPid()); request->SendResult(loader_context->GetPid()); } diff --git a/src/launchpad-process-pool/loader_manager.cc b/src/launchpad-process-pool/loader_manager.cc index 8e4fc3e..4ddee1c 100644 --- a/src/launchpad-process-pool/loader_manager.cc +++ b/src/launchpad-process-pool/loader_manager.cc @@ -458,6 +458,13 @@ void LoaderManager::OnAppLabelsChanged() { hydra_context->Prepare(); } } else if (context->GetPid() > 0) { + if (context->RefCount() != 0) { + _W("Except. type(%d), loader_name(%s), pid(%d)", + context->GetType(), context->GetLoaderName().c_str(), + context->GetPid()); + continue; + } + context->Dispose(); context->Prepare(); } diff --git a/src/launchpad-process-pool/process_pool.cc b/src/launchpad-process-pool/process_pool.cc index f8c010f..c7bb40f 100644 --- a/src/launchpad-process-pool/process_pool.cc +++ b/src/launchpad-process-pool/process_pool.cc @@ -25,6 +25,8 @@ #include +#include + #include "launchpad-process-pool/launchpad_args.hh" #include "launchpad-process-pool/log_private.hh" @@ -110,6 +112,8 @@ void ProcessPool::OnExecution() { snprintf(args[0], length, "/usr/bin/%s <%s>", kProcessPool, name_.c_str()); close(pipe_fd_[1]); + std::vector except_fds { pipe_fd_[0] }; + Util::CloseAllFds(except_fds); int ret = WaitForRequest(std::make_unique(pipe_fd_[0])); exit(ret); } diff --git a/src/lib/launchpad-glib/util.cc b/src/lib/launchpad-glib/util.cc index 9ab6d9e..f3ac15a 100644 --- a/src/lib/launchpad-glib/util.cc +++ b/src/lib/launchpad-glib/util.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -469,7 +470,7 @@ std::string Util::GetLibDirectory(const std::string& app_path) { return ""; } -void Util::CloseAllFds() { +void Util::CloseAllFds(const std::vector& except_fds) { int aul_fd = -1; const char* aul_listen_fd = getenv("AUL_LISTEN_FD"); if (aul_listen_fd != nullptr) @@ -486,6 +487,13 @@ void Util::CloseAllFds() { if (fd < 3 || fd == aul_fd) continue; + auto found = std::find_if(except_fds.begin(), except_fds.end(), + [&](int except_fd) { + return except_fd == fd; + }); + if (found != except_fds.end()) + continue; + fds.push_back(fd); } } catch (const fs::filesystem_error& e) { diff --git a/src/lib/launchpad-glib/util.hh b/src/lib/launchpad-glib/util.hh index 9dfeaff..013581c 100644 --- a/src/lib/launchpad-glib/util.hh +++ b/src/lib/launchpad-glib/util.hh @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -41,7 +42,7 @@ class EXPORT_API Util { static int MountResourceDirectories(const AppInfo* app_info); static int WaitTepMount(const AppInfo* app_info); static std::string GetLibDirectory(const std::string& app_path); - static void CloseAllFds(); + static void CloseAllFds(const std::vector& except_fds = {}); static int PrepareAppSocket(); static int PrepareAppIdFile(const AppInfo* app_info); static int SendCmdToAmd(enum AmdCmd cmd); -- 2.7.4 From dfd9ba6d70f04b2eb02f55fe8e9e23d3318caa32 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 11 Aug 2023 17:09:57 +0900 Subject: [PATCH 09/16] Release version 0.36.3 Changes: - Add a missing exception handling - Close all fds while creating process pool Change-Id: I7af928c124425d35a6e99e8a584c58118f8335ef Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index e21611d..4b9695a 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.36.2 +Version: 0.36.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 26b52de45f868f75561cf5ac394e4722d013e769 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 16 Aug 2023 13:58:14 +0900 Subject: [PATCH 10/16] Modify CPUBoostingController This patch removes the RESET_ON_FORK flag. If the flag is set, the scheduling policy is not inherited to the sub thread. Change-Id: I8f63106271907749bdabff033881aab619f2e892 Signed-off-by: Hwankyu Jhun --- src/lib/launchpad-common/cpu_boost_controller.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/launchpad-common/cpu_boost_controller.cc b/src/lib/launchpad-common/cpu_boost_controller.cc index 7ef0119..eb06ffe 100644 --- a/src/lib/launchpad-common/cpu_boost_controller.cc +++ b/src/lib/launchpad-common/cpu_boost_controller.cc @@ -33,8 +33,8 @@ void CPUBoostController::DoBoost(pid_t pid, Level level, int timeout_msec) { }; int ret = resource_set_cpu_boosting(res_pid, - static_cast(level), CPU_BOOSTING_RESET_ON_FORK, - timeout_msec); + static_cast(level), + static_cast(0), timeout_msec); if (ret != 0) _E("resource_set_cpu_boosting() is failed. error: %d", ret); else -- 2.7.4 From c7b0045b49fa404eae846a665f0050c85204ad55 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 17 Aug 2023 10:30:31 +0900 Subject: [PATCH 11/16] Release version 0.36.4 Changes: - Modify CPUBoostingController Change-Id: I744cdf875f803142a9bfb9115625008fa3deed53 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 4b9695a..75e4d3a 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.36.3 +Version: 0.36.4 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 78f5909518b8e89f5a45e68d0e482352ac503289 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 7 Aug 2023 09:16:41 +0900 Subject: [PATCH 12/16] Create ready files of loader process A new function is added to create a ready file of the loader. The function creates the file that the path is "/run/user//..ready". Change-Id: Id2c6181793650c55b866deddbf2c68ff3b43f1d6 Signed-off-by: Hwankyu Jhun --- src/app-defined-loader/app-defined-loader.cc | 6 +++++ src/launchpad-loader/launchpad_loader.cc | 5 ++++ src/launchpad-process-pool/loader_info.cc | 3 +++ src/lib/launchpad/inc/launchpad.h | 14 +++++++++-- src/lib/launchpad/launchpad_loader.cc | 37 +++++++++++++++++++++++++++- src/lib/launchpad/launchpad_loader.hh | 2 ++ 6 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/app-defined-loader/app-defined-loader.cc b/src/app-defined-loader/app-defined-loader.cc index 57e7ffd..5c8ebef 100644 --- a/src/app-defined-loader/app-defined-loader.cc +++ b/src/app-defined-loader/app-defined-loader.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -156,6 +157,11 @@ class AppDefinedLoader { _E("Plugin::PrepareApp() is failed. error(%d)", ret); _exit(EXIT_FAILURE); } + + g_idle_add([](gpointer data) { + launchpad_loader_create_ready_file(); + return G_SOURCE_REMOVE; + }, nullptr); } static int OnLaunch(int argc, char** argv, const char* app_path, diff --git a/src/launchpad-loader/launchpad_loader.cc b/src/launchpad-loader/launchpad_loader.cc index cc62aa1..2cae7ac 100644 --- a/src/launchpad-loader/launchpad_loader.cc +++ b/src/launchpad-loader/launchpad_loader.cc @@ -17,6 +17,7 @@ #include "launchpad-loader/launchpad_loader.hh" #include +#include #include #include @@ -174,6 +175,10 @@ void LaunchpadLoader::OnCreate(const tizen_base::Bundle& extra, int type) { InitializeElementary(); hw_acc_config_.reset(new launchpad::HWAccelerationConfig()); + g_idle_add([](gpointer user_data) { + launchpad_loader_create_ready_file(); + return G_SOURCE_REMOVE; + }, nullptr); } int LaunchpadLoader::OnLaunch(const LaunchArgs& args) { diff --git a/src/launchpad-process-pool/loader_info.cc b/src/launchpad-process-pool/loader_info.cc index df00c5c..4640a0d 100644 --- a/src/launchpad-process-pool/loader_info.cc +++ b/src/launchpad-process-pool/loader_info.cc @@ -27,6 +27,8 @@ #include #include +#include + #include "launchpad-process-pool/log_private.hh" #include "launchpad-process-pool/util.hh" @@ -278,6 +280,7 @@ LoaderInfo::LoaderInfo(LoaderType type, std::string name, std::string exe, on_boot_timeout_(on_boot_timeout), sched_priority_(sched_priority), condition_path_exists_(std::move(condition_path_exists)) { + extra_.Add(kAulLoaderName, name_); } LoaderType LoaderInfo::GetType() const { diff --git a/src/lib/launchpad/inc/launchpad.h b/src/lib/launchpad/inc/launchpad.h index b7d6c21..d95d624 100644 --- a/src/lib/launchpad/inc/launchpad.h +++ b/src/lib/launchpad/inc/launchpad.h @@ -85,7 +85,7 @@ bundle *launchpad_loader_get_bundle(void); * @brief Blocks all sub threads of the loader. * @remarks This function has to be called in the main thread. * - * @return @c on success, + * @return @c 0 on success, * otherwise a negative error value * * @see #launchpad_loader_unblock_threads() @@ -96,12 +96,22 @@ int launchpad_loader_block_threads(void); * @brief Unblocks all sub threads of the loader. * @remarks This function has to be called in the main thread. * - * @return @c on success, + * @return @c 0 on success, * otherwise a negative error value * @see #launchpad_loader_block_threads() */ int launchpad_loader_unblock_threads(void); +/** + * @brief Creates a ready file. + * @details This function creates a ready file. + * The path of the ready file is "/run/user//..ready". + * + * @return @c 0 on success, + * otherwise a negative error value + */ +int launchpad_loader_create_ready_file(void); + #ifdef __cplusplus } #endif diff --git a/src/lib/launchpad/launchpad_loader.cc b/src/lib/launchpad/launchpad_loader.cc index e7d733c..f967ea6 100644 --- a/src/lib/launchpad/launchpad_loader.cc +++ b/src/lib/launchpad/launchpad_loader.cc @@ -22,16 +22,20 @@ #include #include +#include +#include +#include #include #include +#include #include #include #include #include #include -#include #include +#include #include "launchpad/log_private.hh" #include "launchpad/step_prepare_execution.hh" @@ -122,6 +126,10 @@ const tizen_base::Bundle& LaunchpadLoader::GetBundle() const { return app_info_.GetBundle(); } +const std::string& LaunchpadLoader::GetLoaderName() const { + return loader_name_; +} + void LaunchpadLoader::ResetArgs() { memset(argv_[LoaderArg::Type], 0, strlen(argv_[LoaderArg::Type])); memset(argv_[LoaderArg::Id], 0, strlen(argv_[LoaderArg::Id])); @@ -185,6 +193,10 @@ bool LaunchpadLoader::OnCreate() { threads = std::stoi(threads_str); } + loader_name_ = extra.GetString(kAulLoaderName); + if (!loader_name_.empty()) + _W("name: %s", loader_name_.c_str()); + callback_.create(extra.GetHandle(), loader_type_, user_data_); aul_launch_worker_init(); WaitForThreads(threads); @@ -384,3 +396,26 @@ extern "C" EXPORT_API int launchpad_loader_block_threads(void) { extern "C" EXPORT_API int launchpad_loader_unblock_threads(void) { return ThreadControl::GetInst().UnblockThreads(); } + +extern "C" EXPORT_API int launchpad_loader_create_ready_file(void) { + if (!::context) + return -1; + + std::string path = "/run/user/" + std::to_string(getuid()) + "/." + + ::context->GetLoaderName() + ".ready"; + std::filesystem::path file_path(path); + if (std::filesystem::exists(file_path)) { + _D("Already exists. path(%s)", path.c_str()); + return 0; + } + + std::ofstream file_stream(file_path); + if (!file_stream.is_open()) { + _E("Failed to create the file. path(%s)", path.c_str()); + return -1; + } + + file_stream.close(); + _W("File(%s) created successfully", path.c_str()); + return 0; +} diff --git a/src/lib/launchpad/launchpad_loader.hh b/src/lib/launchpad/launchpad_loader.hh index 8f44252..4277d3a 100644 --- a/src/lib/launchpad/launchpad_loader.hh +++ b/src/lib/launchpad/launchpad_loader.hh @@ -41,6 +41,7 @@ class LaunchpadLoader { void* user_data); void Quit(); const tizen_base::Bundle& GetBundle() const; + const std::string& GetLoaderName() const; private: void WaitForThreads(int threads); @@ -68,6 +69,7 @@ class LaunchpadLoader { char** argv_; int loader_type_; int loader_id_; + std::string loader_name_; loader_lifecycle_callback_s callback_ = { nullptr, }; loader_adapter_s adapter_callback_ = { nullptr, }; void* user_data_ = nullptr; -- 2.7.4 From d32f825ecbd2ecce91756cca648f659a07a1371e Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 17 Aug 2023 12:56:53 +0900 Subject: [PATCH 13/16] Create ready file for all loaders When the loader process is connecting to the launchpad-process-pool, the launchpad-process-pool creates a ready file to notify that the loader is ready. Change-Id: Iff44684329682d56782c1b3ffeb9cff1e9425d1e Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/loader_context.cc | 30 +++++++++++++++++++++++++++- src/launchpad-process-pool/loader_context.hh | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/launchpad-process-pool/loader_context.cc b/src/launchpad-process-pool/loader_context.cc index 53e8ab1..b47e57d 100644 --- a/src/launchpad-process-pool/loader_context.cc +++ b/src/launchpad-process-pool/loader_context.cc @@ -21,9 +21,14 @@ #include #include #include +#include #include #include +#include +#include +#include +#include #include #include @@ -632,8 +637,10 @@ void LoaderContext::HandleLoaderEvent() { SetPid(peer_cred->GetPid()); prepared_ = true; - if (listener_ != nullptr) + if (listener_ != nullptr) { + CreateReadyFile(); listener_->OnLoaderPrepared(this); + } SECURE_LOGI("Type %d loader was connected. pid: %d", GetType(), pid_); UserTracer::Print("Type " + std::to_string(GetType()) + @@ -666,4 +673,25 @@ void LoaderContext::OnIOEventReceived(int fd, int condition) { HandleLoaderClientEvent(condition); } +void LoaderContext::CreateReadyFile() { + std::string path = "/run/aul/daemons/" + std::to_string(getuid()) + "/." + + GetLoaderName() + ".ready"; + std::filesystem::path file_path(path); + if (std::filesystem::exists(file_path)) + return; + + std::ofstream file_stream(file_path); + if (!file_stream.is_open()) { + _E("Failed to create the file. path(%s)", path.c_str()); + return; + } + + file_stream.close(); + + if (smack_setlabel(path.c_str(), "*", SMACK_LABEL_ACCESS) != 0) + _E("smack_setlabel() is failed. path: %s, errno: %d", path.c_str(), errno); + + _W("File(%s) created successfully", path.c_str()); +} + } // namespace launchpad diff --git a/src/launchpad-process-pool/loader_context.hh b/src/launchpad-process-pool/loader_context.hh index 15ad2b8..1bba362 100644 --- a/src/launchpad-process-pool/loader_context.hh +++ b/src/launchpad-process-pool/loader_context.hh @@ -115,6 +115,7 @@ class LoaderContext : public std::enable_shared_from_this, void SetPrepared(bool prepared); void OnIOEventReceived(int fd, int condition) override; int GetSchedPriority() const; + void CreateReadyFile(); private: void UpdateScore(); -- 2.7.4 From 9e6ab8cda164199fa01edbd45ed7743a1445cb0b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 17 Aug 2023 12:57:54 +0900 Subject: [PATCH 14/16] Revert "Create ready files of loader process" This reverts commit 78f5909518b8e89f5a45e68d0e482352ac503289. Change-Id: I54e852a6f3f54f2b2c207bd6ad763d60c00d48d3 --- src/app-defined-loader/app-defined-loader.cc | 6 ----- src/launchpad-loader/launchpad_loader.cc | 5 ---- src/launchpad-process-pool/loader_info.cc | 3 --- src/lib/launchpad/inc/launchpad.h | 14 ++--------- src/lib/launchpad/launchpad_loader.cc | 37 +--------------------------- src/lib/launchpad/launchpad_loader.hh | 2 -- 6 files changed, 3 insertions(+), 64 deletions(-) diff --git a/src/app-defined-loader/app-defined-loader.cc b/src/app-defined-loader/app-defined-loader.cc index 5c8ebef..57e7ffd 100644 --- a/src/app-defined-loader/app-defined-loader.cc +++ b/src/app-defined-loader/app-defined-loader.cc @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -157,11 +156,6 @@ class AppDefinedLoader { _E("Plugin::PrepareApp() is failed. error(%d)", ret); _exit(EXIT_FAILURE); } - - g_idle_add([](gpointer data) { - launchpad_loader_create_ready_file(); - return G_SOURCE_REMOVE; - }, nullptr); } static int OnLaunch(int argc, char** argv, const char* app_path, diff --git a/src/launchpad-loader/launchpad_loader.cc b/src/launchpad-loader/launchpad_loader.cc index 2cae7ac..cc62aa1 100644 --- a/src/launchpad-loader/launchpad_loader.cc +++ b/src/launchpad-loader/launchpad_loader.cc @@ -17,7 +17,6 @@ #include "launchpad-loader/launchpad_loader.hh" #include -#include #include #include @@ -175,10 +174,6 @@ void LaunchpadLoader::OnCreate(const tizen_base::Bundle& extra, int type) { InitializeElementary(); hw_acc_config_.reset(new launchpad::HWAccelerationConfig()); - g_idle_add([](gpointer user_data) { - launchpad_loader_create_ready_file(); - return G_SOURCE_REMOVE; - }, nullptr); } int LaunchpadLoader::OnLaunch(const LaunchArgs& args) { diff --git a/src/launchpad-process-pool/loader_info.cc b/src/launchpad-process-pool/loader_info.cc index 4640a0d..df00c5c 100644 --- a/src/launchpad-process-pool/loader_info.cc +++ b/src/launchpad-process-pool/loader_info.cc @@ -27,8 +27,6 @@ #include #include -#include - #include "launchpad-process-pool/log_private.hh" #include "launchpad-process-pool/util.hh" @@ -280,7 +278,6 @@ LoaderInfo::LoaderInfo(LoaderType type, std::string name, std::string exe, on_boot_timeout_(on_boot_timeout), sched_priority_(sched_priority), condition_path_exists_(std::move(condition_path_exists)) { - extra_.Add(kAulLoaderName, name_); } LoaderType LoaderInfo::GetType() const { diff --git a/src/lib/launchpad/inc/launchpad.h b/src/lib/launchpad/inc/launchpad.h index d95d624..b7d6c21 100644 --- a/src/lib/launchpad/inc/launchpad.h +++ b/src/lib/launchpad/inc/launchpad.h @@ -85,7 +85,7 @@ bundle *launchpad_loader_get_bundle(void); * @brief Blocks all sub threads of the loader. * @remarks This function has to be called in the main thread. * - * @return @c 0 on success, + * @return @c on success, * otherwise a negative error value * * @see #launchpad_loader_unblock_threads() @@ -96,22 +96,12 @@ int launchpad_loader_block_threads(void); * @brief Unblocks all sub threads of the loader. * @remarks This function has to be called in the main thread. * - * @return @c 0 on success, + * @return @c on success, * otherwise a negative error value * @see #launchpad_loader_block_threads() */ int launchpad_loader_unblock_threads(void); -/** - * @brief Creates a ready file. - * @details This function creates a ready file. - * The path of the ready file is "/run/user//..ready". - * - * @return @c 0 on success, - * otherwise a negative error value - */ -int launchpad_loader_create_ready_file(void); - #ifdef __cplusplus } #endif diff --git a/src/lib/launchpad/launchpad_loader.cc b/src/lib/launchpad/launchpad_loader.cc index f967ea6..e7d733c 100644 --- a/src/lib/launchpad/launchpad_loader.cc +++ b/src/lib/launchpad/launchpad_loader.cc @@ -22,20 +22,16 @@ #include #include -#include -#include -#include #include #include -#include #include #include #include #include #include -#include #include +#include #include "launchpad/log_private.hh" #include "launchpad/step_prepare_execution.hh" @@ -126,10 +122,6 @@ const tizen_base::Bundle& LaunchpadLoader::GetBundle() const { return app_info_.GetBundle(); } -const std::string& LaunchpadLoader::GetLoaderName() const { - return loader_name_; -} - void LaunchpadLoader::ResetArgs() { memset(argv_[LoaderArg::Type], 0, strlen(argv_[LoaderArg::Type])); memset(argv_[LoaderArg::Id], 0, strlen(argv_[LoaderArg::Id])); @@ -193,10 +185,6 @@ bool LaunchpadLoader::OnCreate() { threads = std::stoi(threads_str); } - loader_name_ = extra.GetString(kAulLoaderName); - if (!loader_name_.empty()) - _W("name: %s", loader_name_.c_str()); - callback_.create(extra.GetHandle(), loader_type_, user_data_); aul_launch_worker_init(); WaitForThreads(threads); @@ -396,26 +384,3 @@ extern "C" EXPORT_API int launchpad_loader_block_threads(void) { extern "C" EXPORT_API int launchpad_loader_unblock_threads(void) { return ThreadControl::GetInst().UnblockThreads(); } - -extern "C" EXPORT_API int launchpad_loader_create_ready_file(void) { - if (!::context) - return -1; - - std::string path = "/run/user/" + std::to_string(getuid()) + "/." + - ::context->GetLoaderName() + ".ready"; - std::filesystem::path file_path(path); - if (std::filesystem::exists(file_path)) { - _D("Already exists. path(%s)", path.c_str()); - return 0; - } - - std::ofstream file_stream(file_path); - if (!file_stream.is_open()) { - _E("Failed to create the file. path(%s)", path.c_str()); - return -1; - } - - file_stream.close(); - _W("File(%s) created successfully", path.c_str()); - return 0; -} diff --git a/src/lib/launchpad/launchpad_loader.hh b/src/lib/launchpad/launchpad_loader.hh index 4277d3a..8f44252 100644 --- a/src/lib/launchpad/launchpad_loader.hh +++ b/src/lib/launchpad/launchpad_loader.hh @@ -41,7 +41,6 @@ class LaunchpadLoader { void* user_data); void Quit(); const tizen_base::Bundle& GetBundle() const; - const std::string& GetLoaderName() const; private: void WaitForThreads(int threads); @@ -69,7 +68,6 @@ class LaunchpadLoader { char** argv_; int loader_type_; int loader_id_; - std::string loader_name_; loader_lifecycle_callback_s callback_ = { nullptr, }; loader_adapter_s adapter_callback_ = { nullptr, }; void* user_data_ = nullptr; -- 2.7.4 From 880808289e0b699c489f4f8c1185a31ab5d8f807 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 17 Aug 2023 13:25:11 +0900 Subject: [PATCH 15/16] Release version 0.36.5 Changes: - Create ready files of loader process - Create ready file for all loaders - Revert "Create ready files of loader process" Change-Id: I142352c805c36c4a5bf212c3c8f5a80f0ef3bcbd Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 75e4d3a..2df8a0a 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.36.4 +Version: 0.36.5 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 5b68f21600680a7875232a878cc1ffaff18b114c Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Thu, 17 Aug 2023 18:10:48 +0900 Subject: [PATCH 16/16] Fix crash issue This patch is for a below crash issue. #3 0xb6d503ce in __GI_abort () at abort.c:79 #4 0xb706dc1c in __gnu_cxx::__verbose_terminate_handler () at ../../../../libstdc++-v3/libsupc++/vterminate.cc:95 #5 0xb707c336 in __cxxabiv1::__terminate ( handler=0xb707e820 <__gnu_cxx::__verbose_terminate_handler()>) at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:47 #6 0xb707c39f in std::terminate () at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:57 #7 0x800b2cba in std::thread::~thread (this=0x810b5a9c, __in_chrg=) at /usr/lib/gcc/i586-tizen-linux-gnu/9.2.0/include/c++/thread:139 #8 launchpad::Worker::~Worker (this=0x810b5a80, __in_chrg=) at /usr/src/debug/launchpad-0.36.3-1.i386/src/launchpad-process-pool/worker.cc:46 #9 0x800b2ce2 in launchpad::Worker::~Worker (this=0x810b5a80, __in_chrg=) at /usr/src/debug/launchpad-0.36.3-1.i386/src/launchpad-process-pool/worker.cc:46 #10 0x8009978c in std::default_delete::operator() ( this=0x800ccb18 , __ptr=) at /usr/lib/gcc/i586-tizen-linux-gnu/9.2.0/include/c++/bits/unique_ptr.h:75 #11 std::unique_ptr >::reset ( __p=, this=0x800ccb18 ) at /usr/lib/gcc/i586-tizen-linux-gnu/9.2.0/include/c++/bits/unique_ptr.h:394 #12 launchpad::SignalManager::Dispose ( this=this@entry=0x800cca00 ) at /usr/src/debug/launchpad-0.36.3-1.i386/src/launchpad-process-pool/signal_manager.cc:121 #13 0x8009983f in launchpad::SignalManager::Dispose ( this=0x800cca00 ) at /usr/src/debug/launchpad-0.36.3-1.i386/src/launchpad-process-pool/signal_manager.cc:171 #14 launchpad::SignalManager::~SignalManager ( this=0x800cca00 , __in_chrg=) at /usr/src/debug/launchpad-0.36.3-1.i386/src/launchpad-process-pool/signal_manager.cc:171 #15 0xb6d6bfff in __run_exit_handlers (status=status@entry=-1, listp=0xb6f0339c <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108 #16 0xb6d6c1d5 in __GI_exit (status=-1) at exit.c:139 #17 0x80096948 in launchpad::ProcessPool::OnExecution (this=) at /usr/src/debug/launchpad-0.36.3-1.i386/src/launchpad-process-pool/process_pool.cc:118 #18 0x80071b03 in launchpad::Executor::Execute (this=this@entry=0x810b8044, priority=priority@entry=0) at /usr/src/debug/launchpad-0.36.3-1.i386/src/launchpad-process-pool/executor.cc:50 #19 0x80096b09 in launchpad::ProcessPool::PrepareProcess (this=0x810b8040) Change-Id: I96ff11d3fb0fc6d368d531e4ecc38bf10135bc84 Signed-off-by: Changgyu Choi --- src/launchpad-process-pool/dbus.cc | 2 ++ src/launchpad-process-pool/worker.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/launchpad-process-pool/dbus.cc b/src/launchpad-process-pool/dbus.cc index da24593..92a2a42 100644 --- a/src/launchpad-process-pool/dbus.cc +++ b/src/launchpad-process-pool/dbus.cc @@ -105,6 +105,8 @@ class DBusManager { } delete queue_; + } else { + thread_.detach(); } disposed_ = true; diff --git a/src/launchpad-process-pool/worker.cc b/src/launchpad-process-pool/worker.cc index 0b2dd45..1a2e972 100644 --- a/src/launchpad-process-pool/worker.cc +++ b/src/launchpad-process-pool/worker.cc @@ -48,6 +48,8 @@ Worker::~Worker() { Add(std::make_shared()); thread_.join(); delete queue_; + } else { + thread_.detach(); } } -- 2.7.4