From e77648b26fd400670e5a9fb852fb395ecdd5e2e5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 31 Aug 2023 08:23:25 +0900 Subject: [PATCH 01/16] Modify ready file path The ready file path is changed to "/tmp/.-.ready". Change-Id: Ia8b59a289b8181be53ef35edb78a89e52c830bb7 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/loader_context.cc | 10 ++++++++-- src/launchpad-process-pool/loader_context.hh | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/launchpad-process-pool/loader_context.cc b/src/launchpad-process-pool/loader_context.cc index b47e57d..10b2b87 100644 --- a/src/launchpad-process-pool/loader_context.cc +++ b/src/launchpad-process-pool/loader_context.cc @@ -674,11 +674,16 @@ void LoaderContext::OnIOEventReceived(int fd, int condition) { } void LoaderContext::CreateReadyFile() { - std::string path = "/run/aul/daemons/" + std::to_string(getuid()) + "/." + + if (ready_file_created_) + return; + + std::string path = "/tmp/." + std::to_string(getuid()) + "-" + GetLoaderName() + ".ready"; std::filesystem::path file_path(path); - if (std::filesystem::exists(file_path)) + if (std::filesystem::exists(file_path)) { + ready_file_created_ = true; return; + } std::ofstream file_stream(file_path); if (!file_stream.is_open()) { @@ -692,6 +697,7 @@ void LoaderContext::CreateReadyFile() { _E("smack_setlabel() is failed. path: %s, errno: %d", path.c_str(), errno); _W("File(%s) created successfully", path.c_str()); + ready_file_created_ = true; } } // namespace launchpad diff --git a/src/launchpad-process-pool/loader_context.hh b/src/launchpad-process-pool/loader_context.hh index 1bba362..feaf15d 100644 --- a/src/launchpad-process-pool/loader_context.hh +++ b/src/launchpad-process-pool/loader_context.hh @@ -154,6 +154,7 @@ class LoaderContext : public std::enable_shared_from_this, std::vector condition_path_exists_; IEvent* listener_ = nullptr; uint32_t ref_count_ = 0; + bool ready_file_created_ = false; }; } // namespace launchpad -- 2.7.4 From ac1616d6b03f30480842989e25af1463ba300e98 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 31 Aug 2023 09:12:19 +0900 Subject: [PATCH 02/16] Release version 0.37.2 Changes: - Modify ready file path Change-Id: I2a6e4eb25fbfc7fc60dd9629dad7c2e51408dbd2 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 7733bf5..eeba3b3 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.37.1 +Version: 0.37.2 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 56af157d856415e171aa6eb6d73a2fe6cae4b82f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 1 Sep 2023 08:01:40 +0900 Subject: [PATCH 03/16] Set reset on fork flag The CPU_BOOSTING_RESET_ON_FORK flag is required in order not to unintentionally inherit the CPU boosting to child processes. Change-Id: Ie0573b18d1e595f7d59e0cc3e76c8784fbceffd4 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 2 +- src/lib/launchpad-common/cpu_boost_controller.cc | 7 ++++--- src/lib/launchpad-common/cpu_boost_controller.hh | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 672bc98..c1f0f9b 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -208,7 +208,7 @@ Launchpad::Launchpad(int argc, char** argv) level == CPUBoostController::Level::None || level == CPUBoostController::Level::Weak) { CPUBoostController::DoBoost(getpid(), CPUBoostController::Level::Strong, - -1); + -1, true); } g_timeout_add(1000, [](gpointer data) { diff --git a/src/lib/launchpad-common/cpu_boost_controller.cc b/src/lib/launchpad-common/cpu_boost_controller.cc index c72d80b..615adbd 100644 --- a/src/lib/launchpad-common/cpu_boost_controller.cc +++ b/src/lib/launchpad-common/cpu_boost_controller.cc @@ -24,7 +24,8 @@ namespace launchpad { -void CPUBoostController::DoBoost(pid_t pid, Level level, int timeout_msec) { +void CPUBoostController::DoBoost(pid_t pid, Level level, int timeout_msec, + bool reset_on_fork) { if (pid < 1) return; @@ -33,10 +34,10 @@ void CPUBoostController::DoBoost(pid_t pid, Level level, int timeout_msec) { .tid = &pid, .tid_count = 1, }; - + int flag = reset_on_fork ? CPU_BOOSTING_RESET_ON_FORK : 0; int ret = resource_set_cpu_boosting(res_pid, static_cast(level), - static_cast(0), timeout_msec); + static_cast(flag), timeout_msec); if (ret != 0) _E("resource_set_cpu_boosting() is failed. error: %d", ret); else diff --git a/src/lib/launchpad-common/cpu_boost_controller.hh b/src/lib/launchpad-common/cpu_boost_controller.hh index ae0df27..715b4bd 100644 --- a/src/lib/launchpad-common/cpu_boost_controller.hh +++ b/src/lib/launchpad-common/cpu_boost_controller.hh @@ -33,7 +33,8 @@ class EXPORT_API CPUBoostController { Weak, }; - static void DoBoost(pid_t pid, Level level, int timeout_msec); + static void DoBoost(pid_t pid, Level level, int timeout_msec, + bool reset_on_fork = false); static void Clear(pid_t pid); static int GetBoostLevel(pid_t pid, Level* level); }; -- 2.7.4 From c08706a5075698321681cc7f3206e99966c26490 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 1 Sep 2023 11:09:46 +0900 Subject: [PATCH 04/16] Release version 0.37.3 Changes: - Set reset on fork flag Change-Id: I505a0e223308029def83ce0458976830e0746144 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 eeba3b3..7b67395 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.37.2 +Version: 0.37.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 10c16111a76745bbcf57e5570ddc9ed95ba9b94d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 11 Sep 2023 12:57:57 +0900 Subject: [PATCH 05/16] Reset scheduling priority This patch removes calling the SchedPriority::Set(0) from the launchpad library. After this patch is applied, the loader process should reset the priority to zero itself. Change-Id: I93b1e435ab4ebbe9d21b790c547010e39321dabe Signed-off-by: Hwankyu Jhun --- src/app-defined-loader/app-defined-loader.cc | 3 +++ src/launchpad-loader/launchpad_loader.cc | 2 ++ src/lib/launchpad/launchpad_loader.cc | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app-defined-loader/app-defined-loader.cc b/src/app-defined-loader/app-defined-loader.cc index a135dc7..1d55100 100644 --- a/src/app-defined-loader/app-defined-loader.cc +++ b/src/app-defined-loader/app-defined-loader.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -156,6 +157,8 @@ class AppDefinedLoader { _E("Plugin::PrepareApp() is failed. error(%d)", ret); _exit(EXIT_FAILURE); } + + SchedPriority::Set(0); } 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 83cb8e3..d1cdf6f 100644 --- a/src/launchpad-loader/launchpad_loader.cc +++ b/src/launchpad-loader/launchpad_loader.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -174,6 +175,7 @@ void LaunchpadLoader::OnCreate(const tizen_base::Bundle& extra, int type) { InitializeElementary(); hw_acc_config_.reset(new launchpad::HWAccelerationConfig()); + SchedPriority::Set(0); } int LaunchpadLoader::OnLaunch(const LaunchArgs& args) { diff --git a/src/lib/launchpad/launchpad_loader.cc b/src/lib/launchpad/launchpad_loader.cc index 57816c2..d6815ef 100644 --- a/src/lib/launchpad/launchpad_loader.cc +++ b/src/lib/launchpad/launchpad_loader.cc @@ -111,7 +111,6 @@ int LaunchpadLoader::Run(loader_lifecycle_callback_s* callback, return -1; } - SchedPriority::Set(0); OnAdapterLoopBegin(); return OnTerminate(); } -- 2.7.4 From 7afc5ce5b384682b0fcac395b2a92e7974449ae2 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 11 Sep 2023 13:34:19 +0900 Subject: [PATCH 06/16] Release version 0.37.4 Changes: - Reset scheduling priority Change-Id: I01bff79963e43ec4bbda4c9ef91d2db9a0578ed8 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 7b67395..f54bfc8 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.37.3 +Version: 0.37.4 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 1bbd868c3e906a043920e7038feae840925231a1 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 13 Sep 2023 19:09:42 +0900 Subject: [PATCH 07/16] Lock and unlock mutex for process creation To prevent memory corruption issue, this patch adds locking and unlocking a mutex. If the memory allocation occurs when creating a children process using fork(), the children process has a memory problem. Change-Id: I6abc980533686421b30a7cbdac52f370cc352748 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/dbus.cc | 2 ++ src/launchpad-process-pool/executor.cc | 2 ++ src/launchpad-process-pool/rec_mutex.hh | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/launchpad-process-pool/rec_mutex.hh diff --git a/src/launchpad-process-pool/dbus.cc b/src/launchpad-process-pool/dbus.cc index 92a2a42..87d19c2 100644 --- a/src/launchpad-process-pool/dbus.cc +++ b/src/launchpad-process-pool/dbus.cc @@ -27,6 +27,7 @@ #include #include "launchpad-process-pool/log_private.hh" +#include "launchpad-process-pool/rec_mutex.hh" namespace launchpad { namespace { @@ -133,6 +134,7 @@ class DBusManager { if (conn_) return conn_; + std::lock_guard lock(RecMutex::GetInst().GetMutex()); GError* error = nullptr; conn_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error); if (conn_ == nullptr) { diff --git a/src/launchpad-process-pool/executor.cc b/src/launchpad-process-pool/executor.cc index 4aea7ca..31496f7 100644 --- a/src/launchpad-process-pool/executor.cc +++ b/src/launchpad-process-pool/executor.cc @@ -22,12 +22,14 @@ #include #include "launchpad-process-pool/log_private.hh" +#include "launchpad-process-pool/rec_mutex.hh" namespace launchpad { Executor::Executor(Executor::Delegator* delegator) : delegator_(delegator) {} pid_t Executor::Execute(int priority) { + std::lock_guard lock(RecMutex::GetInst().GetMutex()); pid_t pid = fork(); if (pid == -1) { _E("Failed to create child process. errno(%d)", errno); diff --git a/src/launchpad-process-pool/rec_mutex.hh b/src/launchpad-process-pool/rec_mutex.hh new file mode 100644 index 0000000..ee0cfda --- /dev/null +++ b/src/launchpad-process-pool/rec_mutex.hh @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 LAUNCHPAD_PROCESS_POOL_REC_MUTEX_HH_ +#define LAUNCHPAD_PROCESS_POOL_REC_MUTEX_HH_ + +#include + +namespace launchpad { + +class RecMutex { + public: + static RecMutex& GetInst() { + static RecMutex inst; + return inst; + } + + std::recursive_mutex& GetMutex() const { + return mutex_; + } + + private: + RecMutex() = default; + ~RecMutex() = default; + + private: + mutable std::recursive_mutex mutex_; +}; + +} // namespace launchpad + +#endif // LAUNCHPAD_PROCESS_POOL_REC_MUTEX_HH_ -- 2.7.4 From 0c4b9a1f09feb8b22e345cbd4a9feac7342f85cb Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Sep 2023 08:44:15 +0900 Subject: [PATCH 08/16] Add a new function for loader termination The launchpad_loader_dispose() function is added to dispose the loader iself. The function sends a disposal request to the launchpad-process-pool. When the launchpad-process-pool gets the request, it sends SIGKILL signal to the running loader process. Change-Id: I74ed0b2b5fa42d47220b335e84fb1776b7b748f5 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 46 +++++++++++++++++++--------- src/launchpad-process-pool/launchpad.hh | 1 + src/launchpad-process-pool/loader_manager.hh | 2 +- src/lib/launchpad-common/types.hh | 1 + src/lib/launchpad/inc/launchpad.h | 14 +++++++-- src/lib/launchpad/launchpad_loader.cc | 28 +++++++++++++++++ src/lib/launchpad/launchpad_loader.hh | 1 + 7 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index c1f0f9b..fdde825 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -197,6 +197,9 @@ Launchpad::Launchpad(int argc, char** argv) { PadCmd::RestartLoader, std::bind(&Launchpad::HandleRestartLoaderRequest, this, std::placeholders::_1) }, + { PadCmd::DisposeLoader, + std::bind(&Launchpad::HandleDisposeLoaderRequest, this, + std::placeholders::_1) }, }; CPUBoostController::Level level; @@ -295,7 +298,7 @@ void Launchpad::OnTerminate() { void Launchpad::HandleVisibilityRequest(std::shared_ptr request) { LoaderManager::GetInst().ActivateLoaderContexts(LoaderMethod::Visibility); request->SendResult(0); - _D("[PAD_CMD_VISIBILITY]"); + _W("[PAD_CMD_VISIBILITY]"); } void Launchpad::HandleAddLoaderRequest(std::shared_ptr request) { @@ -308,7 +311,7 @@ void Launchpad::HandleAddLoaderRequest(std::shared_ptr request) { } request->SendResult(context->GetLoaderId()); - _D("[PAD_CMD_ADD_LOADER]"); + _W("[PAD_CMD_ADD_LOADER]"); } void Launchpad::HandleRemoveLoaderRequest(std::shared_ptr request) { @@ -323,13 +326,13 @@ void Launchpad::HandleRemoveLoaderRequest(std::shared_ptr request) { LoaderManager::GetInst().RemoveLoaderContext(LoaderType::Dynamic, std::stoi(loader_id_str)); request->SendResult(0); - _D("[PAD_CMD_REMOVE_LOADER]"); + _W("[PAD_CMD_REMOVE_LOADER]"); } void Launchpad::HandleMakeDefaultSlotsRequest( std::shared_ptr request) { LoaderManager::GetInst().AddDefaultLoaderContexts(); - _D("[PAD_CMD_MAKE_DEFAULT_SLOTS]"); + _W("[PAD_CMD_MAKE_DEFAULT_SLOTS]"); } void Launchpad::HandlePrepareAppDefinedLoaderRequest( @@ -350,18 +353,18 @@ void Launchpad::HandlePrepareAppDefinedLoaderRequest( } request->SendResult(context->GetLoaderId()); - _D("[PAD_CMD_PREPARE_APP_DEFINED_LOADER] result: %d", context->GetLoaderId()); + _W("[PAD_CMD_PREPARE_APP_DEFINED_LOADER] result: %d", context->GetLoaderId()); } void Launchpad::HandleDemandRequest(std::shared_ptr request) { LoaderManager::GetInst().ActivateLoaderContexts(LoaderMethod::Demand); request->SendResult(0); - _D("[PAD_CMD_DEMAND]"); + _W("[PAD_CMD_DEMAND]"); } void Launchpad::HandlePingRequest(std::shared_ptr request) { request->SendResult(getpid()); - _D("[PAD_CMD_PING]"); + _W("[PAD_CMD_PING]"); } void Launchpad::HandleUpdateAppTypeRequest(std::shared_ptr request) { @@ -376,13 +379,13 @@ void Launchpad::HandleUpdateAppTypeRequest(std::shared_ptr request) { _I("type: %s, installed: %s", app_type.c_str(), installed.c_str()); bool app_installed = (installed == "true") ? true : false; LoaderManager::GetInst().UpdateAppInstallationStatus(app_type, app_installed); - _D("[PAD_CMD_UPDATE_APP_TYPE]"); + _W("[PAD_CMD_UPDATE_APP_TYPE]"); } void Launchpad::HandleConnectRequest(std::shared_ptr request) { client_socket_.reset( new ClientSocket(request->GetClientSocket()->RemoveFd())); - _D("[PAD_CMD_CONNECT] client fd: %d", client_socket_->GetFd()); + _W("[PAD_CMD_CONNECT] client fd: %d", client_socket_->GetFd()); } bool Launchpad::CanUseLoaderContext( @@ -511,6 +514,7 @@ Launchpad::LaunchResult Launchpad::LaunchRequestPend( CPUBoostController::DoBoost(loader_context->GetPid(), CPUBoostController::Level::Strong, 10000); _W("Send result: %d", loader_context->GetPid()); + request->SetPid(loader_context->GetPid()); request->SendResult(loader_context->GetPid()); } @@ -571,7 +575,7 @@ void Launchpad::HandleLaunchRequest(std::shared_ptr request) { return; LaunchRequestComplete(request); - _D("[PAD_CMD_LAUNCH] appid: %s, result: %d", + _W("[PAD_CMD_LAUNCH] appid: %s, result: %d", request->GetAppInfo()->GetAppId().c_str(), request->GetPid()); } @@ -588,7 +592,7 @@ void Launchpad::HandleKillLoaderRequest(std::shared_ptr request) { if (loader_context->RefCount() == 0) loader_context->Dispose(); - _D("[PAD_CMD_KILL_LOADER] loader_name: %s", loader_name.c_str()); + _W("[PAD_CMD_KILL_LOADER] loader_name: %s", loader_name.c_str()); } void Launchpad::HandleRestartLoaderRequest(std::shared_ptr request) { @@ -607,10 +611,24 @@ void Launchpad::HandleRestartLoaderRequest(std::shared_ptr request) { if (loader_context->GetPid() < 1) loader_context->Prepare(); - _D("[PAD_CMD_RESTART_LOADER] loader_name: %s, pid: %d", + _W("[PAD_CMD_RESTART_LOADER] loader_name: %s, pid: %d", loader_name.c_str(), loader_context->GetPid()); } +void Launchpad::HandleDisposeLoaderRequest(std::shared_ptr request) { + pid_t caller_pid = request->GetCallerPid(); + auto loader_context = + LoaderManager::GetInst().FindLoaderContextFromPid(caller_pid); + if (loader_context == nullptr) { + _E("Failed to find loader context. pid(%d)", caller_pid); + return; + } + + loader_context->Dispose(); + _W("[PAD_CMD_DISPOSE_LOADER] loader_name: %s, pid: %d", + loader_context->GetLoaderName().c_str(), caller_pid); +} + void Launchpad::OnIOEventReceived(int fd, int condition) { auto client_socket = socket_->Accept(); if (!client_socket) { @@ -655,10 +673,10 @@ void Launchpad::OnSigchldReceived(pid_t pid) { while (iter != pending_requests_.end()) { auto request = *iter; auto context = request->GetAvailableLoaderContext(); - if (context != nullptr && context->GetPid() == pid) { + if (context != nullptr && request->GetPid() == pid) { context->Unref(); auto* app_info = request->GetAppInfo(); - launchpad::DBus::SendAppLaunchSignal(context->GetPid(), + launchpad::DBus::SendAppLaunchSignal(request->GetPid(), app_info->GetAppId().c_str()); pending_requests_.erase(iter); break; diff --git a/src/launchpad-process-pool/launchpad.hh b/src/launchpad-process-pool/launchpad.hh index acf7670..4e6cb01 100644 --- a/src/launchpad-process-pool/launchpad.hh +++ b/src/launchpad-process-pool/launchpad.hh @@ -78,6 +78,7 @@ class Launchpad : public IOChannel::IEvent, void HandleLaunchRequest(std::shared_ptr request); void HandleKillLoaderRequest(std::shared_ptr request); void HandleRestartLoaderRequest(std::shared_ptr request); + void HandleDisposeLoaderRequest(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 76825ad..7f3f078 100644 --- a/src/launchpad-process-pool/loader_manager.hh +++ b/src/launchpad-process-pool/loader_manager.hh @@ -78,13 +78,13 @@ class LoaderManager : public AppDefinedLoaderInfoManager::IEvent, void RemoveLoaderContext(LoaderType type, int loader_id); std::shared_ptr FindLoaderContextFromName( const std::string& loader_name); + std::shared_ptr FindLoaderContextFromPid(pid_t pid); private: LoaderManager(); ~LoaderManager(); void Init(); - std::shared_ptr FindLoaderContextFromPid(pid_t pid); std::shared_ptr FindHydraLoaderContextFromPid(pid_t pid); std::shared_ptr FindLoaderContextFromLoaderId(int loader_id); std::shared_ptr FindLoaderContextFromType(LoaderType type); diff --git a/src/lib/launchpad-common/types.hh b/src/lib/launchpad-common/types.hh index 7483b36..5b7eada 100644 --- a/src/lib/launchpad-common/types.hh +++ b/src/lib/launchpad-common/types.hh @@ -59,6 +59,7 @@ enum PadCmd { Connect = 18, KillLoader = 19, RestartLoader = 20, + DisposeLoader = 21, }; enum PadLoaderId { diff --git a/src/lib/launchpad/inc/launchpad.h b/src/lib/launchpad/inc/launchpad.h index b7d6c21..ba5867c 100644 --- a/src/lib/launchpad/inc/launchpad.h +++ b/src/lib/launchpad/inc/launchpad.h @@ -88,7 +88,7 @@ bundle *launchpad_loader_get_bundle(void); * @return @c on success, * otherwise a negative error value * - * @see #launchpad_loader_unblock_threads() + * @see launchpad_loader_unblock_threads() */ int launchpad_loader_block_threads(void); @@ -98,10 +98,20 @@ int launchpad_loader_block_threads(void); * * @return @c on success, * otherwise a negative error value - * @see #launchpad_loader_block_threads() + * @see launchpad_loader_block_threads() */ int launchpad_loader_unblock_threads(void); +/** + * @brief Disposes the loader. + * @details This function sends a disposal request to the launchpad. + * The launchpad will dispose the loader process using kill(). + * @since_tizen 7.0 + * + * @see launchpad_loader_main(); + */ +void launchpad_loader_dispose(void); + #ifdef __cplusplus } #endif diff --git a/src/lib/launchpad/launchpad_loader.cc b/src/lib/launchpad/launchpad_loader.cc index d6815ef..766eb22 100644 --- a/src/lib/launchpad/launchpad_loader.cc +++ b/src/lib/launchpad/launchpad_loader.cc @@ -17,6 +17,7 @@ #include "launchpad/launchpad_loader.hh" #include +#include #include #include #include @@ -43,6 +44,8 @@ namespace { const uint32_t kMaxRetryingCount = 600; constexpr const char kLaunchpadLoaderSocketName[] = ".launchpad-type"; +constexpr const char kLaunchpadProcessPoolSock[] = + ".launchpad-process-pool-sock"; tizen_base::Bundle loader_bundle; LaunchpadLoader* context = nullptr; @@ -123,6 +126,21 @@ const tizen_base::Bundle& LaunchpadLoader::GetBundle() const { return app_info_.GetBundle(); } +void LaunchpadLoader::SendDisposalRequest() { + int fd = aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, + getuid()); + if (fd < 0) { + _E("Failed to create launchpad client socket. error(%d)", fd); + return; + } + + tizen_base::Bundle b; + int ret = aul_sock_send_bundle_with_fd(fd, + static_cast(PadCmd::DisposeLoader), b.GetHandle(), AUL_SOCK_NOREPLY); + if (ret != AUL_R_OK) + _E("Failed to send disposal request. error(%d)", ret); +} + void LaunchpadLoader::ResetArgs() { memset(argv_[LoaderArg::Type], 0, strlen(argv_[LoaderArg::Type])); memset(argv_[LoaderArg::Id], 0, strlen(argv_[LoaderArg::Id])); @@ -385,3 +403,13 @@ 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 void launchpad_loader_dispose(void) { + if (!::context) { + _E("Invalid context"); + return; + } + + _W("Dispose"); + ::context->SendDisposalRequest(); +} diff --git a/src/lib/launchpad/launchpad_loader.hh b/src/lib/launchpad/launchpad_loader.hh index 8f44252..c089ab6 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; + void SendDisposalRequest(); private: void WaitForThreads(int threads); -- 2.7.4 From 1a9ff1b5df8aaa648ba328dd9f0b81d3f69cfbf1 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Sep 2023 10:27:04 +0900 Subject: [PATCH 09/16] Modify launchpad_loader_dispose() function The type of the return value is changed to 'int' from 'void'. Change-Id: I7af938e048d36348a9ad6d070c6ab9feaa8e9978 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 2 ++ src/lib/launchpad/inc/launchpad.h | 4 +++- src/lib/launchpad/launchpad_loader.cc | 38 +++++++++++++++------------------ src/lib/launchpad/launchpad_loader.hh | 1 - 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index fdde825..549314e 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -621,12 +621,14 @@ void Launchpad::HandleDisposeLoaderRequest(std::shared_ptr request) { LoaderManager::GetInst().FindLoaderContextFromPid(caller_pid); if (loader_context == nullptr) { _E("Failed to find loader context. pid(%d)", caller_pid); + request->SendResult(-ENOENT); return; } loader_context->Dispose(); _W("[PAD_CMD_DISPOSE_LOADER] loader_name: %s, pid: %d", loader_context->GetLoaderName().c_str(), caller_pid); + request->SendResult(0); } void Launchpad::OnIOEventReceived(int fd, int condition) { diff --git a/src/lib/launchpad/inc/launchpad.h b/src/lib/launchpad/inc/launchpad.h index ba5867c..807381d 100644 --- a/src/lib/launchpad/inc/launchpad.h +++ b/src/lib/launchpad/inc/launchpad.h @@ -108,9 +108,11 @@ int launchpad_loader_unblock_threads(void); * The launchpad will dispose the loader process using kill(). * @since_tizen 7.0 * + * @return @c on success, + * otherwise a negative error value * @see launchpad_loader_main(); */ -void launchpad_loader_dispose(void); +int launchpad_loader_dispose(void); #ifdef __cplusplus } diff --git a/src/lib/launchpad/launchpad_loader.cc b/src/lib/launchpad/launchpad_loader.cc index 766eb22..bfb301b 100644 --- a/src/lib/launchpad/launchpad_loader.cc +++ b/src/lib/launchpad/launchpad_loader.cc @@ -126,21 +126,6 @@ const tizen_base::Bundle& LaunchpadLoader::GetBundle() const { return app_info_.GetBundle(); } -void LaunchpadLoader::SendDisposalRequest() { - int fd = aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, - getuid()); - if (fd < 0) { - _E("Failed to create launchpad client socket. error(%d)", fd); - return; - } - - tizen_base::Bundle b; - int ret = aul_sock_send_bundle_with_fd(fd, - static_cast(PadCmd::DisposeLoader), b.GetHandle(), AUL_SOCK_NOREPLY); - if (ret != AUL_R_OK) - _E("Failed to send disposal request. error(%d)", ret); -} - void LaunchpadLoader::ResetArgs() { memset(argv_[LoaderArg::Type], 0, strlen(argv_[LoaderArg::Type])); memset(argv_[LoaderArg::Id], 0, strlen(argv_[LoaderArg::Id])); @@ -404,12 +389,23 @@ extern "C" EXPORT_API int launchpad_loader_unblock_threads(void) { return ThreadControl::GetInst().UnblockThreads(); } -extern "C" EXPORT_API void launchpad_loader_dispose(void) { - if (!::context) { - _E("Invalid context"); - return; +extern "C" EXPORT_API int launchpad_loader_dispose(void) { + int fd = + aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, getuid()); + if (fd < 0) { + _E("Failed to create launchpad client socket. error(%d)", fd); + return -ECOMM; + } + + tizen_base::Bundle b; + int ret = + aul_sock_send_bundle_with_fd(fd, static_cast(PadCmd::DisposeLoader), + b.GetHandle(), AUL_SOCK_NONE); + if (ret != AUL_R_OK) { + _E("Failed to send disposal request. error(%d)", ret); + return ret; } - _W("Dispose"); - ::context->SendDisposalRequest(); + _W("Success to send disposal request"); + return 0; } diff --git a/src/lib/launchpad/launchpad_loader.hh b/src/lib/launchpad/launchpad_loader.hh index c089ab6..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; - void SendDisposalRequest(); private: void WaitForThreads(int threads); -- 2.7.4 From e8580cd26461c99539deaffbac3b3e85782bfaf6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Sep 2023 10:39:10 +0900 Subject: [PATCH 10/16] Release version 0.38.0 Changes: - Lock and unlock mutex for process creation - Add a new function for loader termination - Modify launchpad_loader_dispose() function Change-Id: I22ea0a0e1b82941effae92af36628655c0ae47fb 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 f54bfc8..30d9e1e 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.37.4 +Version: 0.38.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From b0e616950843dcb3f0ccae794a49487295d96e71 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Sep 2023 19:15:00 +0900 Subject: [PATCH 11/16] Modify disposal loader handler The result should be delivered to the caller before sending SIGKILL signal. Change-Id: I829d244b16aa4472ea6935349c5bf0e1353fc553 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 549314e..90663d6 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -625,10 +625,10 @@ void Launchpad::HandleDisposeLoaderRequest(std::shared_ptr request) { return; } + request->SendResult(0); loader_context->Dispose(); _W("[PAD_CMD_DISPOSE_LOADER] loader_name: %s, pid: %d", loader_context->GetLoaderName().c_str(), caller_pid); - request->SendResult(0); } void Launchpad::OnIOEventReceived(int fd, int condition) { -- 2.7.4 From 223c8caaf7a69b7b0b02ab5cf312bc8b0b84556d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Sep 2023 19:16:47 +0900 Subject: [PATCH 12/16] Release version 0.38.1 Changes: - Modify disposal loader handler Change-Id: I3d849e024e4177fc3314dd3c2a24e24cd6240dc0 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 30d9e1e..20b5cf5 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.38.0 +Version: 0.38.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 5c5ee3684895d4f21035f4f9b49704f0fb0ad4d6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 Sep 2023 07:20:25 +0900 Subject: [PATCH 13/16] Fix static analysis issue Checker: - DEREF_OF_NULL.RET_STAT Change-Id: Ifc95e098d24ccd2d80c83bee5f3340b4e13c5a66 Signed-off-by: Hwankyu Jhun --- src/launchpad-parser/launchpad_parser_plugin.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/launchpad-parser/launchpad_parser_plugin.cc b/src/launchpad-parser/launchpad_parser_plugin.cc index eacfbf2..575afd6 100644 --- a/src/launchpad-parser/launchpad_parser_plugin.cc +++ b/src/launchpad-parser/launchpad_parser_plugin.cc @@ -94,6 +94,9 @@ int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { } xmlNode* root = xmlDocGetRootElement(doc); + if (root == nullptr) + return -1; + for (xmlNode* node = root->children; node; node = node->next) { if (!node->name) continue; -- 2.7.4 From 6ae852b28287922731851bb2a8e06e41550730b4 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 Sep 2023 09:41:41 +0900 Subject: [PATCH 14/16] Release version 0.38.2 Changes: - Fix static analysis issue Change-Id: I99deee4ac9dd219943a7a3bed7f849729c7b184d 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 20b5cf5..f168d44 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.38.1 +Version: 0.38.2 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 476f918ddeca6437d07d11cc717d84817fcfe451 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 Sep 2023 11:01:09 +0900 Subject: [PATCH 15/16] Fix static analysis issues Issues: - COPY_INSTEAD_OF_MOVE Change-Id: I1487405d8664a3fc2b056ac747927eb817943312 Signed-off-by: Hwankyu Jhun --- src/launchpad-parser/launchpad_parser_plugin.cc | 13 +++++++------ src/launchpad-parser/launchpad_parser_plugin.hh | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/launchpad-parser/launchpad_parser_plugin.cc b/src/launchpad-parser/launchpad_parser_plugin.cc index 575afd6..e47adf1 100644 --- a/src/launchpad-parser/launchpad_parser_plugin.cc +++ b/src/launchpad-parser/launchpad_parser_plugin.cc @@ -29,11 +29,11 @@ namespace launchpad_parser_plugin { -std::string LaunchpadParser::GetFilePath(std::string id) { +std::string LaunchpadParser::GetFilePath(const std::string& id) { return "/opt/share/loaders/" + id + ".loader"; } -int LaunchpadParser::WriteToFile(std::string pkgid) { +int LaunchpadParser::WriteToFile(const std::string& pkgid) { if (access(LOADERS_DIRECTORY_PATH, F_OK) != 0) mkdir(LOADERS_DIRECTORY_PATH, 0644); @@ -62,7 +62,8 @@ int LaunchpadParser::WriteToFile(std::string pkgid) { return 0; } -bool LaunchpadParser::IsValidId(std::string loader_id, std::string pkgid) { +bool LaunchpadParser::IsValidId(const std::string& loader_id, + const std::string& pkgid) { std::string needle("../"); size_t found = loader_id.find(needle); if (found != std::string::npos) { @@ -85,7 +86,7 @@ bool LaunchpadParser::IsValidId(std::string loader_id, std::string pkgid) { return false; } -int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { +int LaunchpadParser::Install(xmlDocPtr doc, const std::string& pkgid) { pkgmgr_privilege_level level; pkgmgr_installer_info_get_privilege_level(&level); if (level != PM_PRIVILEGE_PLATFORM) { @@ -143,14 +144,14 @@ int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { return 0; } -int LaunchpadParser::Upgrade(xmlDocPtr doc, std::string pkgid) { +int LaunchpadParser::Upgrade(xmlDocPtr doc, const std::string& pkgid) { if (UnInstall(doc, pkgid) != 0) return -1; return Install(doc, pkgid); } -int LaunchpadParser::UnInstall(xmlDocPtr doc, std::string pkgid) { +int LaunchpadParser::UnInstall(xmlDocPtr doc, const std::string& pkgid) { xmlNode* root = xmlDocGetRootElement(doc); if (root == nullptr) return -1; diff --git a/src/launchpad-parser/launchpad_parser_plugin.hh b/src/launchpad-parser/launchpad_parser_plugin.hh index 483fff0..04bb1c5 100644 --- a/src/launchpad-parser/launchpad_parser_plugin.hh +++ b/src/launchpad-parser/launchpad_parser_plugin.hh @@ -29,12 +29,12 @@ namespace launchpad_parser_plugin { class LaunchpadParser { public: - std::string GetFilePath(std::string id); - int WriteToFile(std::string pkgid); - int Install(xmlDocPtr doc, std::string pkgid); - int Upgrade(xmlDocPtr doc, std::string pkgid); - int UnInstall(xmlDocPtr doc, std::string pkgid); - bool IsValidId(std::string loader_id, std::string pkgid); + std::string GetFilePath(const std::string& id); + int WriteToFile(const std::string& pkgid); + int Install(xmlDocPtr doc, const std::string& pkgid); + int Upgrade(xmlDocPtr doc, const std::string& pkgid); + int UnInstall(xmlDocPtr doc, const std::string& pkgid); + bool IsValidId(const std::string& loader_id, const std::string& pkgid); private: std::list> loader_list_; -- 2.7.4 From 4ee416289a5170947eda6fc0a57d41ba0ea38991 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 20 Sep 2023 10:47:07 +0900 Subject: [PATCH 16/16] Release version 0.38.3 Changes: - Fix static analysis issues Change-Id: I4606ad5f58d7283d2d5e3492febbd9e1b6a57610 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 f168d44..8e504e1 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.38.2 +Version: 0.38.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4