From 9ba1b9946963d7470ceb25e0d051efda1f996302 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 12 Jun 2023 05:20:55 +0000 Subject: [PATCH 01/16] Add missing redirection If calling dlog_connect_fd() is failed, the launchpad should try to redirect fd to null node. Change-Id: I8bb2a2d2a585b7c0e1eff9e3ba958801a5bf49e6 Signed-off-by: Hwankyu Jhun --- src/lib/launchpad-common/stdio.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lib/launchpad-common/stdio.cc b/src/lib/launchpad-common/stdio.cc index 6d3d805..c701f18 100644 --- a/src/lib/launchpad-common/stdio.cc +++ b/src/lib/launchpad-common/stdio.cc @@ -16,10 +16,13 @@ #include "launchpad-common/stdio.hh" -#include #include -#include #include +#include +#include +#include +#include +#include #include #include "launchpad-common/log_private.hh" @@ -27,15 +30,31 @@ namespace launchpad { namespace { +void RedirectToNullNode(int new_fd, int flags) { + int fd = open("/dev/null", flags); + if (fd < 0) { + _E("open() is failed. errno(%d)", errno); + return; + } + + if (dup2(fd, new_fd) < 0) + _E("dup2(%d, %d) is failed. errno(%d)", fd, new_fd, errno); + + close(fd); +} + void Redirect(int fd, const char* ident, int priority) { int ret = dlog_connect_fd(LOG_ID_APPS, fd, ident, priority); - if (ret != 0) + if (ret != 0) { _E("dlog_connect_fd() is failed. error(%d)", ret); + RedirectToNullNode(fd, O_WRONLY | O_NOCTTY); + } } } // namespace void Stdio::Setup() { + RedirectToNullNode(STDIN_FILENO, O_RDONLY | O_NOCTTY); Redirect(STDOUT_FILENO, "STDOUT", DLOG_WARN); Redirect(STDERR_FILENO, "STDERR", DLOG_ERROR); } -- 2.7.4 From 58e6b9ae60c95dda9dc1ccc401008c00dd59daa3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 13 Jun 2023 07:50:16 +0000 Subject: [PATCH 02/16] Modify CloseAllFds method While searching the fd directory using std::filesystem::directory_iterator, we can close the file descriptor of the directory_iterator. In this case, the std::filesystem::filesystem_error exception will be thrown. To avoid throwing the exception, the method uses std::vector to store file descriptors. And then, the method closes all file descriptors using the vector. Change-Id: I281ba065ec1a8b90d90791a31f4abe3e4724fad3 Signed-off-by: Hwankyu Jhun --- src/lib/launchpad-glib/util.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/launchpad-glib/util.cc b/src/lib/launchpad-glib/util.cc index 3db226a..1ba7970 100644 --- a/src/lib/launchpad-glib/util.cc +++ b/src/lib/launchpad-glib/util.cc @@ -468,6 +468,7 @@ void Util::CloseAllFds() { if (aul_listen_fd != nullptr) aul_fd = atoi(aul_listen_fd); + std::vector fds; try { fs::path proc_path("/proc/self/fd"); for (const auto& entry : fs::directory_iterator(proc_path)) { @@ -478,8 +479,11 @@ void Util::CloseAllFds() { if (fd < 3 || fd == aul_fd) continue; - close(fd); + fds.push_back(fd); } + + for (auto fd : fds) + close(fd); } catch (const fs::filesystem_error& e) { _E("Execption occurs. error(%s)", e.what()); } -- 2.7.4 From 8a728ab997707c8b30147af1eccf538bc17f4ae9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 13 Jun 2023 08:16:24 +0000 Subject: [PATCH 03/16] Release version 0.33.3 Changes: - Add missing redirection - Modify CloseAllFds method Change-Id: Ie2e31d409d34a0e82a1f0fc244a6bcb192e9bdf3 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 8ac78a5..383fb81 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.33.2 +Version: 0.33.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 50090cbe54b0437cc7ac7d2eca3f5c896250a28f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 15 Jun 2023 04:34:53 +0000 Subject: [PATCH 04/16] Fix launchpad loader library When the terminate callback returns an error, the launchpad_loader_main() should return with the error value. Change-Id: Iae5cdedb0869e7c4ece0bdb96f026bba2155e59c Signed-off-by: Hwankyu Jhun --- src/lib/launchpad/launchpad_loader.cc | 26 +++++++++++++------------- src/lib/launchpad/launchpad_loader.hh | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/lib/launchpad/launchpad_loader.cc b/src/lib/launchpad/launchpad_loader.cc index a776327..eac8621 100644 --- a/src/lib/launchpad/launchpad_loader.cc +++ b/src/lib/launchpad/launchpad_loader.cc @@ -88,17 +88,17 @@ LaunchpadLoader::~LaunchpadLoader() { context = nullptr; } -void LaunchpadLoader::Run(loader_lifecycle_callback_s* callback, +int LaunchpadLoader::Run(loader_lifecycle_callback_s* callback, loader_adapter_s* adapter, void* user_data) { if (callback == nullptr || adapter == nullptr) { _E("Invalid argument"); - THROW(-EINVAL); + return -EINVAL; } if (adapter->loop_begin == nullptr || adapter->loop_quit == nullptr || adapter->add_fd == nullptr || adapter->remove_fd == nullptr) { _E("Invalid argument. adapter callback is nullptr"); - THROW(-EINVAL); + return -EINVAL; } callback_ = *callback; @@ -107,12 +107,12 @@ void LaunchpadLoader::Run(loader_lifecycle_callback_s* callback, if (!OnCreate()) { _E("OnCreate() returns false"); - THROW(-1); + return -1; } SchedPriority::Set(0); OnAdapterLoopBegin(); - OnTerminate(); + return OnTerminate(); } void LaunchpadLoader::Quit() { @@ -250,16 +250,15 @@ int LaunchpadLoader::OnLaunch(int argc, char** argv, AppInfo* app_info) { app_info->GetPkgType().c_str(), user_data_); } -void LaunchpadLoader::OnTerminate() { +int LaunchpadLoader::OnTerminate() { _D("Terminating..."); region_format_config_.reset(); language_config_.reset(); - if (callback_.terminate != nullptr) { - int ret = callback_.terminate(app_argc_, app_argv_, user_data_); - if (ret != 0) - exit(ret); - } + if (callback_.terminate != nullptr) + return callback_.terminate(app_argc_, app_argv_, user_data_); + + return -1; } void LaunchpadLoader::OnAdapterLoopBegin() { @@ -360,15 +359,16 @@ extern "C" EXPORT_API bundle* launchpad_loader_get_bundle(void) { extern "C" EXPORT_API int launchpad_loader_main(int argc, char** argv, loader_lifecycle_callback_s* callback, loader_adapter_s* adapter, void* user_data) { + int ret = -1; try { LaunchpadLoader loader(argc, argv); - loader.Run(callback, adapter, user_data); + ret = loader.Run(callback, adapter, user_data); } catch (const Exception& e) { _E("Exception occurs. error: %s", e.what()); return e.GetErrorCode(); } - return 0; + return ret; } extern "C" EXPORT_API int launchpad_loader_set_priority(int prio) { diff --git a/src/lib/launchpad/launchpad_loader.hh b/src/lib/launchpad/launchpad_loader.hh index 6e77eaa..8f44252 100644 --- a/src/lib/launchpad/launchpad_loader.hh +++ b/src/lib/launchpad/launchpad_loader.hh @@ -37,7 +37,7 @@ class LaunchpadLoader { LaunchpadLoader(int argc, char** argv); virtual ~LaunchpadLoader(); - void Run(loader_lifecycle_callback_s* callback, loader_adapter_s* adapter, + int Run(loader_lifecycle_callback_s* callback, loader_adapter_s* adapter, void* user_data); void Quit(); const tizen_base::Bundle& GetBundle() const; @@ -52,7 +52,7 @@ class LaunchpadLoader { bool OnCreate(); void OnPrelaunch(int argc, char** argv, AppInfo* app_info); int OnLaunch(int argc, char** argv, AppInfo* app_info); - void OnTerminate(); + int OnTerminate(); void OnAdapterLoopBegin(); void OnAdapterLoopQuit(); -- 2.7.4 From ea6b8b8bbd7234cd7808689e823049b5bee25a3f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 15 Jun 2023 04:51:54 +0000 Subject: [PATCH 05/16] Release version 0.33.4 Changes: - Fix launchpad loader library Change-Id: I8c39382631b5f04ce17394b803b1e5f5767edbc4 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 383fb81..6113e09 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.33.3 +Version: 0.33.4 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 02e70912d79139a01df4aa06a013084b24460da5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 16 Jun 2023 02:29:51 +0000 Subject: [PATCH 06/16] Add debugging logs This patch is for debugging. Change-Id: I49cda06d89c00a4c4c645bd4bee55c4ec14edd4f Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/app_executor.cc | 2 ++ src/lib/launchpad-glib/util.cc | 2 ++ src/lib/launchpad/step_prepare_execution.cc | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/launchpad-process-pool/app_executor.cc b/src/launchpad-process-pool/app_executor.cc index cd58dde..cd5c0c7 100644 --- a/src/launchpad-process-pool/app_executor.cc +++ b/src/launchpad-process-pool/app_executor.cc @@ -180,8 +180,10 @@ int AppExecutor::StepEnableExternalPackage() { } int AppExecutor::StepEnableTrustAnchor() { + _W("trust_anchor_launch ++ %s", app_info_->GetAppId().c_str()); int ret = trust_anchor_launch(app_info_->GetPkgId().c_str(), app_info_->IsGlobal() ? GLOBAL_USER : getuid()); + _W("trust_anchor_launch -- %s", app_info_->GetAppId().c_str()); if (ret != TRUST_ANCHOR_ERROR_NONE && ret != TRUST_ANCHOR_ERROR_NOT_INSTALLED) { _E("trust_anchor_launch() returns %d", ret); diff --git a/src/lib/launchpad-glib/util.cc b/src/lib/launchpad-glib/util.cc index 1ba7970..3cad34b 100644 --- a/src/lib/launchpad-glib/util.cc +++ b/src/lib/launchpad-glib/util.cc @@ -259,6 +259,7 @@ class ExternalPackage : public DBus { } void Enable() { + _I("BEGIN"); int result = -1; int retry_count = 0; auto message = std::unique_ptr( @@ -278,6 +279,7 @@ class ExternalPackage : public DBus { _D("Result: %d", result); if (result < 0) THROW(-EIO); + _I("END"); } private: diff --git a/src/lib/launchpad/step_prepare_execution.cc b/src/lib/launchpad/step_prepare_execution.cc index 88d2fa0..ac8baa2 100644 --- a/src/lib/launchpad/step_prepare_execution.cc +++ b/src/lib/launchpad/step_prepare_execution.cc @@ -86,8 +86,10 @@ int StepPrepareExecution::EnableExternalPackage(AppInfo* app_info) { } int StepPrepareExecution::TrustAnchorLaunch(AppInfo* app_info) { + _W("trust_anchor_launch ++ %s", app_info->GetAppId().c_str()); int ret = trust_anchor_launch(app_info->GetPkgId().c_str(), app_info->IsGlobal() ? GLOBAL_USER : getuid()); + _W("trust_anchor_launch -- %s", app_info->GetAppId().c_str()); if (ret != TRUST_ANCHOR_ERROR_NONE && ret != TRUST_ANCHOR_ERROR_NOT_INSTALLED) { _E("trust_anchor_launch() is failed. error: %d", ret); -- 2.7.4 From 5a5d7d3e1d58d4d81b7aca9a0622e998e5b579ee Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 16 Jun 2023 04:18:21 +0000 Subject: [PATCH 07/16] Release version 0.33.5 Changes: - Add debugging logs Change-Id: If35e15ebf6a582d7ea9de732da10fde9d9f171f7 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 6113e09..283daa9 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.33.4 +Version: 0.33.5 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 1dc85728cba36ed3eb65810bc9dc8016060dc5d5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 16 Jun 2023 05:56:21 +0000 Subject: [PATCH 08/16] Initialize threads before running main loop This patch adds the DBus::Init() call in the OnCreate() of Launchpad to avoid a blocking issue of the child process. If a new child process is creating while creating the thread, the child process can be blocked when the child process tries to allocate the memory. The initialization of the cleaner thread is moved. Change-Id: I3c93eca912c69051523651a8b9892eaf4b718b8a Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/dbus.cc | 17 ++++++++++++----- src/launchpad-process-pool/dbus.hh | 2 ++ src/launchpad-process-pool/launchpad.cc | 7 +++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/launchpad-process-pool/dbus.cc b/src/launchpad-process-pool/dbus.cc index ef6b38c..3bf7bff 100644 --- a/src/launchpad-process-pool/dbus.cc +++ b/src/launchpad-process-pool/dbus.cc @@ -88,7 +88,6 @@ class DBusManager { static DBusManager& GetInst() { static DBusManager inst; - inst.Init(); return inst; } @@ -115,10 +114,6 @@ class DBusManager { queue_->Push(std::move(message)); } - private: - DBusManager() = default; - ~DBusManager() { Dispose(); } - void Init() { if (!disposed_) return; @@ -128,6 +123,10 @@ class DBusManager { disposed_ = false; } + private: + DBusManager() = default; + ~DBusManager() { Dispose(); } + GDBusConnection* GetConnection() { if (conn_) return conn_; @@ -215,4 +214,12 @@ void DBus::SendAppDeadSignal(pid_t pid) { g_variant_new("(u)", pid), "App Dead. " + std::to_string(pid))); } +void DBus::Init() { + DBusManager::GetInst().Init(); +} + +void DBus::Finish() { + DBusManager::GetInst().Dispose(); +} + } // namespace launchpad diff --git a/src/launchpad-process-pool/dbus.hh b/src/launchpad-process-pool/dbus.hh index dd54090..032165b 100644 --- a/src/launchpad-process-pool/dbus.hh +++ b/src/launchpad-process-pool/dbus.hh @@ -26,6 +26,8 @@ namespace launchpad { class DBus { public: + static void Init(); + static void Finish(); static void SendAppLaunchSignal(pid_t pid, const std::string_view appid); static void SendAppDeadSignal(pid_t pid); }; diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 39be747..8a24ddd 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -256,6 +256,9 @@ bool Launchpad::OnCreate() { return false; } + cleaner_.reset(new Worker("cleaner+")); + DBus::Init(); + LoaderManager::GetInst().AddDefaultLoaderContexts(); LoaderManager::GetInst().SetEventListener(this); launchpad::Debug::GetInst().Init(); @@ -264,20 +267,20 @@ bool Launchpad::OnCreate() { lang_config_.reset(new LanguageConfig()); region_format_config_.reset(new RegionFormatConfig()); - cleaner_.reset(new Worker("cleaner+")); Log::Init(); return true; } void Launchpad::OnTerminate() { Log::Finish(); - cleaner_.reset(); region_format_config_.reset(); lang_config_.reset(); pid_map_.clear(); Util::SendCmdToAmd(AmdCmd::LaunchpadDeadSignal); Debug::GetInst().Dispose(); + DBus::Finish(); + cleaner_.reset(); LoaderManager::GetInst().Dispose(); channel_.reset(); -- 2.7.4 From 050809ffc08e2e6528d7775be248e11cd788e697 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 16 Jun 2023 06:24:03 +0000 Subject: [PATCH 09/16] Release version 0.33.6 Changes: - Initialize threads before running main loop Change-Id: I9f563531f086d24474421c06db15dba133709fe6 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 283daa9..e3aa440 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.33.5 +Version: 0.33.6 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 7fcf3d1484af7816820789890a82cb9b89b38893 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Sun, 18 Jun 2023 22:42:57 +0000 Subject: [PATCH 10/16] Revert "Add debugging logs" This reverts commit 02e70912d79139a01df4aa06a013084b24460da5. The issue was related to memory creation in the sub thread. Change-Id: Ie019f0e2e13b5489f789631168bd68f9a3ed2c96 --- src/launchpad-process-pool/app_executor.cc | 2 -- src/lib/launchpad-glib/util.cc | 2 -- src/lib/launchpad/step_prepare_execution.cc | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/launchpad-process-pool/app_executor.cc b/src/launchpad-process-pool/app_executor.cc index cd5c0c7..cd58dde 100644 --- a/src/launchpad-process-pool/app_executor.cc +++ b/src/launchpad-process-pool/app_executor.cc @@ -180,10 +180,8 @@ int AppExecutor::StepEnableExternalPackage() { } int AppExecutor::StepEnableTrustAnchor() { - _W("trust_anchor_launch ++ %s", app_info_->GetAppId().c_str()); int ret = trust_anchor_launch(app_info_->GetPkgId().c_str(), app_info_->IsGlobal() ? GLOBAL_USER : getuid()); - _W("trust_anchor_launch -- %s", app_info_->GetAppId().c_str()); if (ret != TRUST_ANCHOR_ERROR_NONE && ret != TRUST_ANCHOR_ERROR_NOT_INSTALLED) { _E("trust_anchor_launch() returns %d", ret); diff --git a/src/lib/launchpad-glib/util.cc b/src/lib/launchpad-glib/util.cc index 3cad34b..1ba7970 100644 --- a/src/lib/launchpad-glib/util.cc +++ b/src/lib/launchpad-glib/util.cc @@ -259,7 +259,6 @@ class ExternalPackage : public DBus { } void Enable() { - _I("BEGIN"); int result = -1; int retry_count = 0; auto message = std::unique_ptr( @@ -279,7 +278,6 @@ class ExternalPackage : public DBus { _D("Result: %d", result); if (result < 0) THROW(-EIO); - _I("END"); } private: diff --git a/src/lib/launchpad/step_prepare_execution.cc b/src/lib/launchpad/step_prepare_execution.cc index ac8baa2..88d2fa0 100644 --- a/src/lib/launchpad/step_prepare_execution.cc +++ b/src/lib/launchpad/step_prepare_execution.cc @@ -86,10 +86,8 @@ int StepPrepareExecution::EnableExternalPackage(AppInfo* app_info) { } int StepPrepareExecution::TrustAnchorLaunch(AppInfo* app_info) { - _W("trust_anchor_launch ++ %s", app_info->GetAppId().c_str()); int ret = trust_anchor_launch(app_info->GetPkgId().c_str(), app_info->IsGlobal() ? GLOBAL_USER : getuid()); - _W("trust_anchor_launch -- %s", app_info->GetAppId().c_str()); if (ret != TRUST_ANCHOR_ERROR_NONE && ret != TRUST_ANCHOR_ERROR_NOT_INSTALLED) { _E("trust_anchor_launch() is failed. error: %d", ret); -- 2.7.4 From b235b9a76b37e3b4524af2a0c27fee993fa37f78 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 19 Jun 2023 01:02:38 +0000 Subject: [PATCH 11/16] Release version 0.33.7 Changes: - Revert "Add debugging logs" Change-Id: I96ba296e5eb18ef87b040d4e46f84ef0adabffc8 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 e3aa440..7b0c8b9 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.33.6 +Version: 0.33.7 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 406e66e2d919f0b814d3875bdd4a035ad4d3e0fc Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Fri, 16 Jun 2023 12:38:39 +0900 Subject: [PATCH 12/16] Add status to AUL_DBUS_APPDEAD_SIGNAL When an app terminates, launchpad sends app_dead signals including exit status. Change-Id: I0ab5a0ccdbe8a0266c257dc40a0f96b03c184b11 Signed-off-by: Changgyu Choi --- src/launchpad-process-pool/dbus.cc | 11 ++++++----- src/launchpad-process-pool/dbus.hh | 2 +- src/launchpad-process-pool/signal_manager.cc | 8 ++++---- src/launchpad-process-pool/signal_manager.hh | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/launchpad-process-pool/dbus.cc b/src/launchpad-process-pool/dbus.cc index 3bf7bff..36b02b9 100644 --- a/src/launchpad-process-pool/dbus.cc +++ b/src/launchpad-process-pool/dbus.cc @@ -207,11 +207,12 @@ void DBus::SendAppLaunchSignal(pid_t pid, const std::string_view appid) { "App Launch. " + std::to_string(pid) + ":" + std::string(appid))); } -void DBus::SendAppDeadSignal(pid_t pid) { - DBusManager::GetInst().Send( - std::make_shared( - AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL, - g_variant_new("(u)", pid), "App Dead. " + std::to_string(pid))); +void DBus::SendAppDeadSignal(pid_t pid, int status) { + DBusManager::GetInst().Send(std::make_shared( + AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL, + g_variant_new("(ii)", pid, status), + "App Dead. pid: " + std::to_string(pid) + + ", status: " + std::to_string(status))); } void DBus::Init() { diff --git a/src/launchpad-process-pool/dbus.hh b/src/launchpad-process-pool/dbus.hh index 032165b..a5f17c7 100644 --- a/src/launchpad-process-pool/dbus.hh +++ b/src/launchpad-process-pool/dbus.hh @@ -29,7 +29,7 @@ class DBus { static void Init(); static void Finish(); static void SendAppLaunchSignal(pid_t pid, const std::string_view appid); - static void SendAppDeadSignal(pid_t pid); + static void SendAppDeadSignal(pid_t pid, int status); }; } // namespace launchpad diff --git a/src/launchpad-process-pool/signal_manager.cc b/src/launchpad-process-pool/signal_manager.cc index ade60ef..81ea1b0 100644 --- a/src/launchpad-process-pool/signal_manager.cc +++ b/src/launchpad-process-pool/signal_manager.cc @@ -193,19 +193,19 @@ int SignalManager::GetSigchldFd() { return sfd; } -void SignalManager::HandleSigchld(pid_t pid) { - DBus::SendAppDeadSignal(pid); +void SignalManager::HandleSigchld(pid_t pid, int status) { + DBus::SendAppDeadSignal(pid, status); recycle_bin_->Add(std::make_shared(pid)); } void SignalManager::OnSigchld(pid_t pid, int status) { _D("pid: %d, status: %d", pid, status); - HandleSigchld(pid); + HandleSigchld(pid, status); } void SignalManager::OnHydraSigchld(pid_t pid, int status) { _D("pid: %d, status: %d", pid, status); - HandleSigchld(pid); + HandleSigchld(pid, status); } } // namespace launchpad diff --git a/src/launchpad-process-pool/signal_manager.hh b/src/launchpad-process-pool/signal_manager.hh index 0af613d..8cd8ffc 100644 --- a/src/launchpad-process-pool/signal_manager.hh +++ b/src/launchpad-process-pool/signal_manager.hh @@ -58,7 +58,7 @@ class SignalManager : public SigchldEvent::IEvent, ~SignalManager(); void Init(); - void HandleSigchld(pid_t pid); + void HandleSigchld(pid_t pid, int status); int GetSigchldFd(); int BlockSigchld(); -- 2.7.4 From 8a90e8420035cbaac7e15f48f1a61ff9b8164df2 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 19 Jun 2023 05:33:31 +0000 Subject: [PATCH 13/16] Modify app-defined-loader The app-defined-loader uses the launchpad library. This patch removes codes of lib/common directory. Change-Id: Ied95a2cc31afb66796a47e4108af81fb1632f709 Signed-off-by: Hwankyu Jhun --- src/app-defined-loader/CMakeLists.txt | 20 +- .../{src => }/app-defined-loader.cc | 118 +- src/app-defined-loader/{src => }/log-private.hh | 8 +- src/app-defined-loader/src/config.cc | 36 - src/app-defined-loader/src/config.hh | 40 - src/app-defined-loader/src/proc.cc | 50 - src/app-defined-loader/src/proc.hh | 37 - src/lib/common/inc/key.h | 61 - src/lib/common/inc/launchpad_common.h | 157 -- src/lib/common/inc/launchpad_plugin.h | 32 - src/lib/common/inc/launchpad_proc.h | 34 - src/lib/common/inc/launchpad_socket.h | 52 - src/lib/common/inc/launchpad_types.h | 56 - src/lib/common/inc/log_private.h | 47 - src/lib/common/inc/perf.h | 63 - src/lib/common/inc/preexec.h | 181 --- src/lib/common/src/launchpad_common.c | 1545 -------------------- src/lib/common/src/launchpad_plugin.c | 63 - src/lib/common/src/launchpad_proc.c | 192 --- src/lib/common/src/launchpad_socket.c | 407 ------ 20 files changed, 70 insertions(+), 3129 deletions(-) rename src/app-defined-loader/{src => }/app-defined-loader.cc (73%) rename src/app-defined-loader/{src => }/log-private.hh (79%) delete mode 100644 src/app-defined-loader/src/config.cc delete mode 100644 src/app-defined-loader/src/config.hh delete mode 100644 src/app-defined-loader/src/proc.cc delete mode 100644 src/app-defined-loader/src/proc.hh delete mode 100644 src/lib/common/inc/key.h delete mode 100644 src/lib/common/inc/launchpad_common.h delete mode 100644 src/lib/common/inc/launchpad_plugin.h delete mode 100644 src/lib/common/inc/launchpad_proc.h delete mode 100644 src/lib/common/inc/launchpad_socket.h delete mode 100644 src/lib/common/inc/launchpad_types.h delete mode 100644 src/lib/common/inc/log_private.h delete mode 100644 src/lib/common/inc/perf.h delete mode 100644 src/lib/common/inc/preexec.h delete mode 100644 src/lib/common/src/launchpad_common.c delete mode 100644 src/lib/common/src/launchpad_plugin.c delete mode 100644 src/lib/common/src/launchpad_proc.c delete mode 100644 src/lib/common/src/launchpad_socket.c diff --git a/src/app-defined-loader/CMakeLists.txt b/src/app-defined-loader/CMakeLists.txt index a7fa8bb..8edd568 100644 --- a/src/app-defined-loader/CMakeLists.txt +++ b/src/app-defined-loader/CMakeLists.txt @@ -1,10 +1,10 @@ -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") @@ -19,11 +19,6 @@ ENDIF(_TIZEN_FEATURE_PRELINK) 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 @@ -36,7 +31,8 @@ APPLY_PKG_CONFIG(${TARGET_APP_DEFINED_LOADER} PUBLIC 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 diff --git a/src/app-defined-loader/src/app-defined-loader.cc b/src/app-defined-loader/app-defined-loader.cc similarity index 73% rename from src/app-defined-loader/src/app-defined-loader.cc rename to src/app-defined-loader/app-defined-loader.cc index 3841cde..cfef14a 100644 --- a/src/app-defined-loader/src/app-defined-loader.cc +++ b/src/app-defined-loader/app-defined-loader.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * 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. @@ -22,30 +22,31 @@ #include #include #include -#include #include #include -#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" +#include +#include +#include +#include +#include +#include -#ifndef PR_TASK_PERF_USER_TRACE -#define PR_TASK_PERF_USER_TRACE 666 -#endif +#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 uint32_t DEFAULT_THRESHOLD = 25600; // kB +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 { @@ -63,11 +64,10 @@ class AppDefinedLoader { adapter_->add_fd = OnAddFd; adapter_->remove_fd = OnRemoveFd; - proc_ = std::make_unique(getpid()); - Config conf(PATH_CONF); - int threshold = conf.GetIntValue(SECTION_MEMORY, KEY_THRESHOLD); - if (threshold > 0) - threshold_ = static_cast(threshold); + IniParser parser(PATH_CONF); + auto value = parser.Get(SECTION_MEMORY, KEY_THRESHOLD); + if (!value.empty()) + threshold_ = static_cast(std::stoi(value)); else _W("Failed to get threshold"); } @@ -100,6 +100,11 @@ class AppDefinedLoader { 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 so_array = data.GetStringArray("preload"); @@ -115,9 +120,10 @@ class AppDefinedLoader { else _D("preload %s# - handle : %p", i.c_str(), handle); - uint32_t pss = proc_->GetPss(); + uint64_t pss; + launchpad::Procfs::GetPssMemory(getpid(), &pss); if (pss > threshold_) { - _W("Pss(%u) is over threshold(%u)", pss, threshold_); + _W("Pss(%llu) is over threshold(%llu)", pss, threshold_); break; } } @@ -127,7 +133,7 @@ class AppDefinedLoader { _I("on create"); AppDefinedLoader* loader = static_cast(user_data); tizen_base::Bundle ex = tizen_base::Bundle(extra, false, false); - std::string loader_type = ex.GetString(KEY_LOADER_TYPE); + std::string loader_type = ex.GetString(kLoaderType); if (loader_type.empty()) { _E("No loader type"); return; @@ -137,14 +143,14 @@ class AppDefinedLoader { ecore_init(); setenv("AUL_LOADER_INIT", "1", 1); - if (loader_type == LOADER_TYPE_SW) + if (loader_type == kLoaderTypeSw) setenv("AUL_HWACC", "none", 1); - else if (loader_type == LOADER_TYPE_HW) + else if (loader_type == kLoaderTypeHw) setenv("AUL_HWACC", "hw", 1); - int ret = _launchpad_plugin_prepare_app(nullptr, extra); + int ret = launchpad::Plugin::PrepareApp(nullptr, ex); if (ret != 0) { - _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret); + _E("Plugin::PrepareApp() is failed. error(%d)", ret); exit(EXIT_FAILURE); } } @@ -158,53 +164,48 @@ class AppDefinedLoader { return 0; tizen_base::Bundle data(kb, false, false); - std::string high_priority = data.GetString(AUL_K_HIGHPRIORITY); + std::string high_priority = data.GetString(launchpad::kAulHighPriority); if (high_priority == "true") launchpad_loader_set_priority(-12); - data.Delete(AUL_K_HIGHPRIORITY); + + data.Delete(launchpad::kAulHighPriority); 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)) { + char err_str[128]; + if (access(argv_[0], 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))); + argv_[0], errno, strerror_r(errno, err_str, sizeof(err_str))); } else { - SECURE_LOGD("[candidate] Exec application (%s)", - argv_[LOADER_ARG_PATH]); - _close_all_fds(); + 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_[LOADER_ARG_PATH], argv_) < 0) { + if (execv(argv_[0], 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))); + 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) { - 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]); + 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_[LOADER_ARG_PATH], dlerror()); + _E("dlopen(%s) is failed. error(%s)", argv_[0], 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()); - + launchpad::UserTracer::Print(std::to_string(getpid()) + "|lib loading end"); if (restore && chdir(old_cwd.c_str())) _E("failed to chdir: %d", errno); @@ -222,8 +223,7 @@ class AppDefinedLoader { } static int OnTerminate(int argc, char** argv, void* user_data) { - SECURE_LOGD("[candidate] Launch real application (%s)", - argv[LOADER_ARG_PATH]); + SECURE_LOGD("[candidate] Launch real application (%s)", argv[0]); char old_cwd[PATH_MAX] = {0, }; AppDefinedLoader* loader = static_cast(user_data); loader->argc_ = argc; @@ -233,8 +233,8 @@ class AppDefinedLoader { _E("getcwd() is failed"); loader->DoDlOpen(false, old_cwd, ""); } else { - char* libdir = _get_libdir(argv[LOADER_ARG_PATH]); - if (libdir == NULL) { + 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. @@ -242,12 +242,11 @@ class AppDefinedLoader { * so here we change working directory to find shared libraries well. */ bool restore = false; - if (chdir(libdir)) + if (chdir(lib_dir.c_str())) _E("failed to chdir: %d", errno); else restore = true; - std::string libdir_str = std::string(libdir); - free(libdir); + std::string libdir_str = std::move(lib_dir); return loader->DoDlOpen(restore, old_cwd, libdir_str); } } @@ -314,16 +313,15 @@ class AppDefinedLoader { std::shared_ptr adapter_ = nullptr; loader_receiver_cb receiver_cb_ = nullptr; Ecore_Fd_Handler* fd_handler_ = nullptr; - std::unique_ptr proc_; - uint32_t threshold_ = DEFAULT_THRESHOLD; + uint64_t threshold_ = DEFAULT_THRESHOLD; int argc_; char** argv_; }; +} // namespace loader } // 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); + launchpad::loader::AppDefinedLoader loader(argc, argv); + return loader.Run(); } diff --git a/src/app-defined-loader/src/log-private.hh b/src/app-defined-loader/log-private.hh similarity index 79% rename from src/app-defined-loader/src/log-private.hh rename to src/app-defined-loader/log-private.hh index ee448ce..868ca6e 100644 --- a/src/app-defined-loader/src/log-private.hh +++ b/src/app-defined-loader/log-private.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * 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. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef LOG_PRIVATE_HH_ -#define LOG_PRIVATE_HH_ +#ifndef APP_DEFINED_LOADER_LOG_PRIVATE_HH_ +#define APP_DEFINED_LOADER_LOG_PRIVATE_HH_ #include @@ -44,4 +44,4 @@ #endif #define _D LOGD -#endif // LOG_PRIVATE_HH_ +#endif // APP_DEFINED_LOADER_LOG_PRIVATE_HH_ diff --git a/src/app-defined-loader/src/config.cc b/src/app-defined-loader/src/config.cc deleted file mode 100644 index 2a03202..0000000 --- a/src/app-defined-loader/src/config.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 - -#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 diff --git a/src/app-defined-loader/src/config.hh b/src/app-defined-loader/src/config.hh deleted file mode 100644 index f68e17d..0000000 --- a/src/app-defined-loader/src/config.hh +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 - -#include -#include - -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 d_; -}; - -} // namespace launchpad - -#endif // CONFIG_HH_ diff --git a/src/app-defined-loader/src/proc.cc b/src/app-defined-loader/src/proc.cc deleted file mode 100644 index 9719cea..0000000 --- a/src/app-defined-loader/src/proc.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 -#include - -#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 diff --git a/src/app-defined-loader/src/proc.hh b/src/app-defined-loader/src/proc.hh deleted file mode 100644 index 4ffb1a5..0000000 --- a/src/app-defined-loader/src/proc.hh +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 - -namespace launchpad { - -class Proc { - public: - Proc(int pid); - virtual ~Proc(); - - uint32_t GetPss() const; - - private: - int pid_; -}; - -} // namespace launchpad - -#endif // PROC_HH_ diff --git a/src/lib/common/inc/key.h b/src/lib/common/inc/key.h deleted file mode 100644 index cde7c3f..0000000 --- a/src/lib/common/inc/key.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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__ */ diff --git a/src/lib/common/inc/launchpad_common.h b/src/lib/common/inc/launchpad_common.h deleted file mode 100644 index 4a16938..0000000 --- a/src/lib/common/inc/launchpad_common.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include - -#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__ */ diff --git a/src/lib/common/inc/launchpad_plugin.h b/src/lib/common/inc/launchpad_plugin.h deleted file mode 100644 index d8b7123..0000000 --- a/src/lib/common/inc/launchpad_plugin.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 - -#ifdef __cplusplus -extern "C" { -#endif - -int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb); - -#ifdef __cplusplus -} -#endif - -#endif /* __LAUNCHPAD_PLUGIN_H__ */ diff --git a/src/lib/common/inc/launchpad_proc.h b/src/lib/common/inc/launchpad_proc.h deleted file mode 100644 index fe2b9ad..0000000 --- a/src/lib/common/inc/launchpad_proc.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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__ */ diff --git a/src/lib/common/inc/launchpad_socket.h b/src/lib/common/inc/launchpad_socket.h deleted file mode 100644 index b90de31..0000000 --- a/src/lib/common/inc/launchpad_socket.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 - -#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__ */ diff --git a/src/lib/common/inc/launchpad_types.h b/src/lib/common/inc/launchpad_types.h deleted file mode 100644 index 29157a8..0000000 --- a/src/lib/common/inc/launchpad_types.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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__ */ - diff --git a/src/lib/common/inc/log_private.h b/src/lib/common/inc/log_private.h deleted file mode 100644 index c3b0662..0000000 --- a/src/lib/common/inc/log_private.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 - -#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__ */ diff --git a/src/lib/common/inc/perf.h b/src/lib/common/inc/perf.h deleted file mode 100644 index ca87d12..0000000 --- a/src/lib/common/inc/perf.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 - -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__ */ - diff --git a/src/lib/common/inc/preexec.h b/src/lib/common/inc/preexec.h deleted file mode 100644 index 2cf7e86..0000000 --- a/src/lib/common/inc/preexec.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 -#include -#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 diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c deleted file mode 100644 index 9f75801..0000000 --- a/src/lib/common/src/launchpad_common.c +++ /dev/null @@ -1,1545 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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; -} diff --git a/src/lib/common/src/launchpad_plugin.c b/src/lib/common/src/launchpad_plugin.c deleted file mode 100644 index 30f41c3..0000000 --- a/src/lib/common/src/launchpad_plugin.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 -#include -#include -#include -#include - -#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; -} diff --git a/src/lib/common/src/launchpad_proc.c b/src/lib/common/src/launchpad_proc.c deleted file mode 100644 index e390b2b..0000000 --- a/src/lib/common/src/launchpad_proc.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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; -} diff --git a/src/lib/common/src/launchpad_socket.c b/src/lib/common/src/launchpad_socket.c deleted file mode 100644 index 16241f7..0000000 --- a/src/lib/common/src/launchpad_socket.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#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; -} -- 2.7.4 From 1d2b925bb4383e5fad0aed457f9ce0ec727851bb Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 19 Jun 2023 03:37:28 +0000 Subject: [PATCH 14/16] Refactor launchpad loader The launchpad-loader is implemented using C++ language. Change-Id: I9882c1c80fabd0ae81cb26fe4ac1dd72a0c19911 Signed-off-by: Hwankyu Jhun --- src/launchpad-loader/CMakeLists.txt | 15 +- src/launchpad-loader/launch_args.cc | 57 +++ src/launchpad-loader/launch_args.hh | 49 +++ src/launchpad-loader/launchpad_loader.cc | 399 +++++++++++++++++ src/launchpad-loader/launchpad_loader.hh | 93 ++++ src/launchpad-loader/log_private.hh | 37 ++ src/launchpad-loader/main.cc | 22 + src/launchpad-loader/src/launchpad_loader.c | 470 --------------------- src/launchpad-process-pool/app_executor.cc | 4 +- src/launchpad-process-pool/launchpad.cc | 2 +- src/launchpad-process-pool/loader_context.cc | 2 +- src/launchpad-process-pool/loader_factory.cc | 2 +- src/launchpad-process-pool/loader_manager.hh | 3 +- .../launchpad-common}/user_tracer.cc | 2 +- .../launchpad-common}/user_tracer.hh | 6 +- .../launchpad-glib}/hw_acceleration_config.cc | 4 +- .../launchpad-glib}/hw_acceleration_config.hh | 6 +- src/lib/launchpad-glib/util.cc | 4 +- src/lib/launchpad-glib/util.hh | 2 +- 19 files changed, 682 insertions(+), 497 deletions(-) create mode 100644 src/launchpad-loader/launch_args.cc create mode 100644 src/launchpad-loader/launch_args.hh create mode 100644 src/launchpad-loader/launchpad_loader.cc create mode 100644 src/launchpad-loader/launchpad_loader.hh create mode 100644 src/launchpad-loader/log_private.hh create mode 100644 src/launchpad-loader/main.cc delete mode 100644 src/launchpad-loader/src/launchpad_loader.c rename src/{launchpad-process-pool => lib/launchpad-common}/user_tracer.cc (95%) rename src/{launchpad-process-pool => lib/launchpad-common}/user_tracer.hh (85%) rename src/{launchpad-process-pool => lib/launchpad-glib}/hw_acceleration_config.cc (91%) rename src/{launchpad-process-pool => lib/launchpad-glib}/hw_acceleration_config.hh (83%) diff --git a/src/launchpad-loader/CMakeLists.txt b/src/launchpad-loader/CMakeLists.txt index 091bba7..890a266 100644 --- a/src/launchpad-loader/CMakeLists.txt +++ b/src/launchpad-loader/CMakeLists.txt @@ -1,17 +1,13 @@ -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src LAUNCHPAD_LOADER_SRCS) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../lib/common/src - LIB_COMMON_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} LAUNCHPAD_LOADER_SRCS) -ADD_EXECUTABLE(${TARGET_LAUNCHPAD_LOADER} - ${LAUNCHPAD_LOADER_SRCS} - ${LIB_COMMON_SRCS}) +ADD_EXECUTABLE(${TARGET_LAUNCHPAD_LOADER} ${LAUNCHPAD_LOADER_SRCS}) SET_TARGET_PROPERTIES(${TARGET_LAUNCHPAD_LOADER} PROPERTIES SKIP_BUILD_RPATH TRUE) TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCHPAD_LOADER} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR}/../lib/launchpad/inc) -TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCHPAD_LOADER} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/../lib/common/inc) IF(_TIZEN_FEATURE_PRELINK) MESSAGE(STATUS "prelink enable") @@ -38,7 +34,8 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_LOADER} PUBLIC LIBCAP_DEPS ) -TARGET_LINK_LIBRARIES(${TARGET_LAUNCHPAD_LOADER} PRIVATE ${TARGET_LAUNCHPAD}) +TARGET_LINK_LIBRARIES(${TARGET_LAUNCHPAD_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 diff --git a/src/launchpad-loader/launch_args.cc b/src/launchpad-loader/launch_args.cc new file mode 100644 index 0000000..c0b8685 --- /dev/null +++ b/src/launchpad-loader/launch_args.cc @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#include "launchpad-loader/launch_args.hh" + +namespace launchpad { +namespace loader { + +LaunchArgs::LaunchArgs(int argc, char** argv, std::string app_path, + std::string app_id, std::string pkg_id, std::string pkg_type) + : argc_(argc), + argv_(argv), + app_path_(std::move(app_path)), + app_id_(std::move(app_id)), + pkg_id_(std::move(pkg_id)), + pkg_type_(std::move(pkg_type)) { +} + +int LaunchArgs::GetArgc() const { + return argc_; +} + +char** LaunchArgs::GetArgv() const { + return argv_; +} + +const std::string& LaunchArgs::GetAppPath() const { + return app_path_; +} + +const std::string& LaunchArgs::GetAppId() const { + return app_id_; +} + +const std::string& LaunchArgs::GetPkgId() const { + return pkg_id_; +} + +const std::string& LaunchArgs::GetPkgType() const { + return pkg_type_; +} + +} // namespace loader +} // namespace launchpad diff --git a/src/launchpad-loader/launch_args.hh b/src/launchpad-loader/launch_args.hh new file mode 100644 index 0000000..0308a58 --- /dev/null +++ b/src/launchpad-loader/launch_args.hh @@ -0,0 +1,49 @@ +/* + * 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_LOADER_LAUNCH_ARGS_HH_ +#define LAUNCHPAD_LOADER_LAUNCH_ARGS_HH_ + +#include + +namespace launchpad { +namespace loader { + +class LaunchArgs { + public: + LaunchArgs(int argc, char** argv, std::string app_path, std::string app_id, + std::string pkg_id, std::string pkg_type); + + int GetArgc() const; + char** GetArgv() const; + const std::string& GetAppPath() const; + const std::string& GetAppId() const; + const std::string& GetPkgId() const; + const std::string& GetPkgType() const; + + private: + int argc_; + char** argv_; + std::string app_path_; + std::string app_id_; + std::string pkg_id_; + std::string pkg_type_; +}; + +} // namespace loader +} // namespace launchpad + +#endif // LAUNCHPAD_LOADER_LAUNCH_ARGS_HH_ diff --git a/src/launchpad-loader/launchpad_loader.cc b/src/launchpad-loader/launchpad_loader.cc new file mode 100644 index 0000000..43a95c7 --- /dev/null +++ b/src/launchpad-loader/launchpad_loader.cc @@ -0,0 +1,399 @@ +/* + * 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. + */ + +#include "launchpad-loader/launchpad_loader.hh" + +#include + +#include +#include +#include +#include + +#include "launchpad-loader/log_private.hh" + +namespace launchpad { +namespace loader { +namespace { + +constexpr const char kLoaderType[] = "loader_type"; +constexpr const char kLoaderTypeCommmon[] = "common-loader"; +constexpr const char kLoaderTypeHw[] = "hw-loader"; +constexpr const char kLoaderTypeSw[] = "sw-loader"; + +void PreloadLibraries(const tizen_base::Bundle& extra) { + auto libs = extra.GetStringArray("preload"); + if (libs.empty()) + return; + + uint64_t mem_pss; + launchpad::Procfs::GetPssMemory(getpid(), &mem_pss); + _W("PSS: %llu kB", mem_pss); + for (auto& lib : libs) { + if (lib.empty()) + continue; + + void* handle = dlopen(lib.c_str(), RTLD_NOW | RTLD_NODELETE); + if (handle == nullptr) { + _E("dlopen() is failed. path: %s, error: %s", lib.c_str(), dlerror()); + continue; + } + + launchpad::Procfs::GetPssMemory(getpid(), &mem_pss); + _W("Preload %s# - handle: %p, PSS: %llu kB", lib.c_str(), handle, mem_pss); + } +} + +} // namespace + +LaunchpadLoader::LaunchpadLoader(int argc, char** argv) + : argc_(argc), argv_(argv) { +} + +int LaunchpadLoader::Run() { + loader_lifecycle_callback_s callback; + callback.create = LoaderCreateCb; + callback.prelaunch = LoaderPreLaunchCb; + callback.launch = LoaderLaunchCb; + callback.terminate = LoaderTerminateCb; + + loader_adapter_s adapter; + adapter.loop_begin = AdapterLoopBeginCb; + adapter.loop_quit = AdapterLoopQuitCb; + adapter.add_fd = AdapterAddFdCb; + adapter.remove_fd = AdapterRemoveFdCb; + + return launchpad_loader_main(argc_, argv_, &callback, &adapter, this); +} + +void LaunchpadLoader::InitializeTheme() { + _D("Initialize Theme"); + + char* theme = elm_theme_list_item_path_get( + reinterpret_cast(eina_list_data_get(elm_theme_list_get(nullptr))), + nullptr); + if (!edje_file_group_exists(theme, "*")) + _E("theme path: %s", theme); + + free(theme); +} + +void LaunchpadLoader::FinalizeWindow() { + _D("Finalize window"); + + if (conform_ != nullptr) { + evas_object_del(conform_); + conform_ = nullptr; + elm_conformant_precreated_object_set(nullptr); + } + + if (bg_ != nullptr) { + evas_object_del(bg_); + bg_ = nullptr; + elm_bg_precreated_object_set(nullptr); + } + + if (win_ != nullptr) { + evas_object_del(win_); + win_ = nullptr; + elm_win_precreated_object_set(nullptr); + } +} + +void LaunchpadLoader::InitializeWindow() { + _D("Initialize Window"); + + win_ = elm_win_add(nullptr, "package_name", ELM_WIN_BASIC); + if (win_ == nullptr) { + _E("elm_win_add() is failed"); + return; + } + elm_win_precreated_object_set(win_); + + bg_ = elm_bg_add(win_); + if (bg_ == nullptr) { + _E("elm_bg_add() is failed"); + } else { + evas_object_size_hint_weight_set(bg_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win_, bg_); + elm_bg_precreated_object_set(bg_); + } + + conform_ = elm_conformant_add(win_); + if (conform_ == nullptr) { + _E("elm_conformant_add() is failed"); + } else { + evas_object_size_hint_weight_set(conform_, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_conformant_precreated_object_set(conform_); + } +} + +void LaunchpadLoader::InitializeElementary() { + int ret = elm_init(argc_, argv_); + _D("elm_init() returned: %d", ret); + setenv("AUL_LOADER_INIT", "1", 1); + + if (loader_type_ == kLoaderTypeSw) { + elm_config_accel_preference_set("none"); + setenv("AUL_HWACC", "none", 1); + InitializeWindow(); + } else if (loader_type_ == kLoaderTypeHw) { + elm_config_accel_preference_set("hw"); + setenv("AUL_HWACC", "hw", 1); + InitializeWindow(); + } else { + InitializeTheme(); + } +} + +void LaunchpadLoader::OnCreate(const tizen_base::Bundle& extra, int type) { + _D("Create"); + loader_type_ = extra.GetString(kLoaderType); + if (loader_type_.empty()) { + _E("loader type is empty"); + return; + } + + _D("Loader type: %s", loader_type_.c_str()); + PreloadLibraries(extra); + InitializeElementary(); + + hw_acc_config_.reset(new launchpad::HWAccelerationConfig()); +} + +int LaunchpadLoader::OnLaunch(const LaunchArgs& args) { + _D("Launch"); + elm_app_name_set(args.GetAppId().c_str()); + + bundle* kb = launchpad_loader_get_bundle(); + if (kb == nullptr) + return 0; + + tizen_base::Bundle b(kb, false, false); +#ifdef TIZEN_FEATURE_PRIORITY_CHANGE + auto high_priority = b.GetString(kAulHighPrioirty); + if (high_priority == "true") + launchpad_loader_set_priority(-12); + + b.Delete(kAulHighPiority); +#endif // TIZEN_FEATURE_PRIORITY_CHANGE + + auto hwacc = b.GetString(launchpad::kAulHwAcc); + if (hwacc.empty()) + return 0; + + std::string loader_type; + if ((hwacc == "USE") || + (hwacc == "SYS" && hw_acc_config_->Get() == SETTING_HW_ACCELERATION_ON)) + loader_type = kLoaderTypeHw; + else + loader_type = kLoaderTypeSw; + + if (loader_type != loader_type_) + FinalizeWindow(); + + return 0; +} + +void LaunchpadLoader::ChangeCurrentWorkingDirectory(const std::string& dir) { + if (dir.empty()) + return; + + char old_cwd[PATH_MAX]; + if (getcwd(old_cwd, sizeof(old_cwd)) == nullptr) { + _E("getcwd() is failed. errno(%d)", errno); + return; + } + + old_cwd_ = old_cwd; + if (chdir(dir.c_str()) != 0) + _E("chdir() is failed. errno(%d)", errno); +} + +void LaunchpadLoader::RestoreCurrentWorkingDirectory() { + if (old_cwd_.empty()) + return; + + if (chdir(old_cwd_.c_str()) != 0) + _E("chdir() is failed. errno(%d)", errno); +} + +int LaunchpadLoader::DoDlopen(int argc, char** argv, + const std::string& lib_dir, bool* do_exec) { + ChangeCurrentWorkingDirectory(lib_dir); + launchpad::UserTracer::Print(std::to_string(getpid()) + "|lib loading start"); + void* handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL| RTLD_NODELETE); + if (handle == nullptr) { + _E("dlopen() is failed. path(%s), error(%s)", argv[0], dlerror()); + *do_exec = true; + return -1; + } + + dlerror(); + RestoreCurrentWorkingDirectory(); + + auto* dl_main = reinterpret_cast(dlsym(handle, "main")); + if (dl_main == nullptr) { + _E("dlsym() is failed. Please export 'main' function. error(%s)", + dlerror()); + dlclose(handle); + *do_exec = true; + return -1; + } + + launchpad::UserTracer::Print(std::to_string(getpid()) + "|lib loading end"); + return dl_main(argc, argv); +} + +int LaunchpadLoader::DoExec(int argc, char** argv, const std::string& lib_dir) { + if (access(argv[0], F_OK | R_OK) != 0) + SECURE_LOGE("access() is failed. path(%s), errno(%d)", argv[0], errno); + + SECURE_LOGD("Execute application. path(%s)", argv[0]); + Util::CloseAllFds(); + if (!lib_dir.empty()) + setenv("LD_LIBRARY_PATH", lib_dir.c_str(), 1); + + unsetenv("AUL_LOADER_INIT"); + unsetenv("AUL_HWACC"); + if (execv(argv[0], argv) < 0) { + char err_buf[1024]; + fprintf(stderr, "Failed to execute a file. path: %s, errno: %d(%s)\n", + argv[0], errno, strerror_r(errno, err_buf, sizeof(err_buf))); + exit(EXIT_FAILURE); + } + + return 0; +} + +int LaunchpadLoader::OnTerminate(int argc, char** argv) { + _D("Terminate"); + std::string lib_dir = Util::GetLibDirectory(argv[0]); + bool do_exec = false; + int ret = DoDlopen(argc, argv, lib_dir, &do_exec); + if (do_exec) + ret = DoExec(argc, argv, lib_dir); + + return ret; +} + +void LaunchpadLoader::OnAdapterLoopBegin() { + ecore_main_loop_begin(); +} + +void LaunchpadLoader::OnAdapterLoopQuit() { + ecore_main_loop_quit(); +} + +void LaunchpadLoader::OnAdapterAddFd(int fd, loader_receiver_cb receiver) { + fd_handler_ = ecore_main_fd_handler_add(fd, + static_cast(ECORE_FD_READ | ECORE_FD_ERROR), + ProcessFdHandler, this, nullptr, nullptr); + if (fd_handler_ == nullptr) { + _E("fd handler is nullptr"); + close(fd); + exit(-1); + } + + receiver_ = receiver; +} + +void LaunchpadLoader::OnAdapterRemoveFd(int fd) { + if (fd_handler_) { + ecore_main_fd_handler_del(fd_handler_); + fd_handler_ = nullptr; + receiver_ = nullptr; + } +} + +void LaunchpadLoader::OnProcessFdHandler(int fd) { + if (receiver_) + receiver_(fd); +} + +Eina_Bool LaunchpadLoader::ProcessFdHandler(void* user_data, + Ecore_Fd_Handler* handler) { + int fd = ecore_main_fd_handler_fd_get(handler); + if (fd == -1) { + _E("Failed to get fd from fd handler"); + exit(-1); + } + + if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) { + auto* loader = static_cast(user_data); + loader->OnProcessFdHandler(fd); + } else if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR)) { + _E("ECORE_FD_ERROR"); + close(fd); + exit(-1); + } + + return ECORE_CALLBACK_CANCEL; +} + +void LaunchpadLoader::LoaderCreateCb(bundle* extra, int type, void* user_data) { + if (extra == nullptr) { + _E("extra is nullptr"); + return; + } + + auto* loader = static_cast(user_data); + loader->OnCreate(tizen_base::Bundle(extra, false, false), type); +} + +int LaunchpadLoader::LoaderPreLaunchCb(int argc, char** argv, + const char* app_path, const char* appid, const char* pkgid, + const char* pkg_type, void* user_data) { + return 0; +} + +int LaunchpadLoader::LoaderLaunchCb(int argc, char** argv, const char* app_path, + const char* appid, const char* pkgid, const char* pkg_type, + void* user_data) { + LaunchArgs args(argc, argv, app_path, appid, pkgid, pkg_type); + auto* loader = static_cast(user_data); + return loader->OnLaunch(args); +} + +int LaunchpadLoader::LoaderTerminateCb(int argc, char** argv, void* user_data) { + auto* loader = static_cast(user_data); + return loader->OnTerminate(argc, argv); +} + +void LaunchpadLoader::AdapterLoopBeginCb(void* user_data) { + auto* loader = static_cast(user_data); + loader->OnAdapterLoopBegin(); +} + +void LaunchpadLoader::AdapterLoopQuitCb(void* user_data) { + auto* loader = static_cast(user_data); + loader->OnAdapterLoopQuit(); +} + +void LaunchpadLoader::AdapterAddFdCb(void* user_data, int fd, + loader_receiver_cb receiver) { + auto* loader = static_cast(user_data); + loader->OnAdapterAddFd(fd, receiver); +} + +void LaunchpadLoader::AdapterRemoveFdCb(void* user_data, int fd) { + auto* loader = static_cast(user_data); + loader->OnAdapterRemoveFd(fd); +} + +} // namespace loader +} // namespace launchpad diff --git a/src/launchpad-loader/launchpad_loader.hh b/src/launchpad-loader/launchpad_loader.hh new file mode 100644 index 0000000..3af2b5e --- /dev/null +++ b/src/launchpad-loader/launchpad_loader.hh @@ -0,0 +1,93 @@ +/* + * 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_LOADER_LAUNCHPAD_LOADER_HH_ +#define LAUNCHPAD_LOADER_LAUNCHPAD_LOADER_HH_ + +#include +#include +#include +#include + +#include +#include + +#include + +#include "launchpad-loader/launch_args.hh" + +namespace launchpad { +namespace loader { + +class LaunchpadLoader { + public: + LaunchpadLoader(int argc, char** argv); + + int Run(); + + private: + void OnCreate(const tizen_base::Bundle& extra, int type); + int OnLaunch(const LaunchArgs& args); + int OnTerminate(int argc, char** argv); + + void OnAdapterLoopBegin(); + void OnAdapterLoopQuit(); + void OnAdapterAddFd(int fd, loader_receiver_cb receiver); + void OnAdapterRemoveFd(int fd); + void OnProcessFdHandler(int fd); + + void InitializeElementary(); + void InitializeWindow(); + void FinalizeWindow(); + void InitializeTheme(); + void ChangeCurrentWorkingDirectory(const std::string& lib_dir); + void RestoreCurrentWorkingDirectory(); + int DoDlopen(int argc, char** argv, const std::string& lib_dir, + bool* do_exec); + int DoExec(int argc, char** argv, const std::string& lib_dir); + + static Eina_Bool ProcessFdHandler(void* user_data, Ecore_Fd_Handler* handler); + static void LoaderCreateCb(bundle* extra, int type, void* user_data); + static int LoaderPreLaunchCb(int argc, char** argv, const char* app_path, + const char* appid, const char* pkgid, const char* pkg_type, + void* user_data); + static int LoaderLaunchCb(int argc, char** argv, const char* app_path, + const char* appid, const char* pkgid, const char* pkg_type, + void* user_data); + static int LoaderTerminateCb(int argc, char** argv, void* user_data); + static void AdapterLoopBeginCb(void* user_data); + static void AdapterLoopQuitCb(void* user_data); + static void AdapterAddFdCb(void* user_data, int fd, + loader_receiver_cb receiver); + static void AdapterRemoveFdCb(void* user_data, int fd); + + private: + int argc_; + char** argv_; + std::string loader_type_; + loader_receiver_cb receiver_ = nullptr; + Ecore_Fd_Handler* fd_handler_ = nullptr; + Evas_Object* win_ = nullptr; + Evas_Object* bg_ = nullptr; + Evas_Object* conform_ = nullptr; + std::unique_ptr hw_acc_config_; + std::string old_cwd_; +}; + +} // namespace loader +} // namespace launchpad + +#endif // LAUNCHPAD_LOADER_LAUNCHPAD_LOADER_HH_ diff --git a/src/launchpad-loader/log_private.hh b/src/launchpad-loader/log_private.hh new file mode 100644 index 0000000..efb2ead --- /dev/null +++ b/src/launchpad-loader/log_private.hh @@ -0,0 +1,37 @@ +/* + * 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_LOADER_LOG_PRIVATE_HH_ +#define LAUNCHPAD_LOADER_LOG_PRIVATE_HH_ + +#include + +#undef LOG_TAG +#define LOG_TAG "LAUNCHPAD_LOADER" + +#undef _E +#define _E LOGE + +#undef _W +#define _W LOGW + +#undef _I +#define _I LOGI + +#undef _D +#define _D LOGD + +#endif // LAUNCHPAD_LOADER_LOG_PRIVATE_HH_ diff --git a/src/launchpad-loader/main.cc b/src/launchpad-loader/main.cc new file mode 100644 index 0000000..ee10069 --- /dev/null +++ b/src/launchpad-loader/main.cc @@ -0,0 +1,22 @@ +/* + * 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. + */ + +#include "launchpad-loader/launchpad_loader.hh" + +int main(int argc, char** argv) { + launchpad::loader::LaunchpadLoader loader(argc, argv); + return loader.Run(); +} diff --git a/src/launchpad-loader/src/launchpad_loader.c b/src/launchpad-loader/src/launchpad_loader.c deleted file mode 100644 index 87f1d3c..0000000 --- a/src/launchpad-loader/src/launchpad_loader.c +++ /dev/null @@ -1,470 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "launchpad_common.h" -#include "launchpad_types.h" -#include "launchpad_proc.h" -#include "launchpad.h" -#include "key.h" - -#ifndef PR_TASK_PERF_USER_TRACE -#define PR_TASK_PERF_USER_TRACE 666 -#endif - -#define PATH_LIB_VC_ELM LIBDIR"/libvc-elm.so.0" - -extern bundle *launchpad_loader_get_bundle(void); - -static Ecore_Fd_Handler *__fd_handler; -static loader_receiver_cb __receiver; - -static int __argc; -static char **__argv; -static int __sys_hwacc; -static Evas_Object *__win; -static Evas_Object *__bg; -static Evas_Object *__conform; -static int __type; - -enum loader_type { - TYPE_COMMON, - TYPE_SW, - TYPE_HW, - MAX_LOADER_TYPE -}; - -enum acc_type { - SW_ACC, - HW_ACC, - MAX_ACC_TYPE -}; - -typedef void (*loader_convertible)(void); - -static void __vconf_cb(keynode_t *key, void *data) -{ - const char *name; - - name = vconf_keynode_get_name(key); - if (name && strcmp(name, VCONFKEY_SETAPPL_APP_HW_ACCELERATION) == 0) { - __sys_hwacc = vconf_keynode_get_int(key); - _D("sys hwacc: %d", __sys_hwacc); - } -} - -static void __init_theme(void) -{ - char *theme = elm_theme_list_item_path_get(eina_list_data_get( - elm_theme_list_get(NULL)), NULL); - Eina_Bool is_exist = edje_file_group_exists(theme, "*"); - - if (!is_exist) - _D("theme path: %s", theme); - - if (theme) - free(theme); -} - -static void __init_window(void) -{ - __win = elm_win_add(NULL, "package_name", ELM_WIN_BASIC); - if (__win == NULL) { - _E("[candidate] elm_win_add() failed"); - return; - } - - elm_win_precreated_object_set(__win); - - __bg = elm_bg_add(__win); - if (__bg) { - evas_object_size_hint_weight_set(__bg, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - elm_win_resize_object_add(__win, __bg); - elm_bg_precreated_object_set(__bg); - } else { - _E("[candidate] elm_bg_add() failed"); - } - - __conform = elm_conformant_add(__win); - if (__conform) { - evas_object_size_hint_weight_set(__conform, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - elm_conformant_precreated_object_set(__conform); - } else { - _E("elm_conformant_add() failed"); - } -} - -static void __fini_window(void) -{ - _D("Drop window"); - - if (__conform) { - evas_object_del(__conform); - elm_conformant_precreated_object_set(NULL); - __conform = NULL; - } - - if (__bg) { - evas_object_del(__bg); - elm_bg_precreated_object_set(NULL); - __bg = NULL; - } - - if (__win) { - evas_object_del(__win); - elm_win_precreated_object_set(NULL); - __win = NULL; - } -} - -static void __preload_lib(bundle *b) -{ - void *handle = NULL; - int i; - int len = 0; - const char **so_array; - unsigned int mem_pss = 0; - - if (!b) - return; - - so_array = bundle_get_str_array(b, "preload", &len); - - if (!so_array) - return; - - _proc_get_mem_pss(getpid(), &mem_pss); - _W("PSS: %u kB", mem_pss); - for (i = 0; i < len; i++) { - if (!so_array[i]) { - _E("so_array[%d] is nullptr", i); - continue; - } - if (so_array[i][0] == '\0') { - _E("so_array[%d] is empty string", i); - continue; - } - - handle = dlopen(so_array[i], RTLD_NOW | RTLD_NODELETE); - if (!handle) { - _E("failed to load: %s, err: %s", - so_array[i], dlerror()); - } else { - _proc_get_mem_pss(getpid(), &mem_pss); - _W("preload %s# - handle : %p, PSS: %u kB", - so_array[i], handle, mem_pss); - } - } -} - -static void __loader_create_cb(bundle *extra, int type, void *user_data) -{ - int elm_init_cnt = 0; - int ret; - char *ltype = NULL; - - if (extra == NULL) { - _E("No extra data"); - return; - } - - bundle_get_str(extra, KEY_LOADER_TYPE, <ype); - - if (ltype == NULL) { - _E("No loader type"); - return; - } - - if (!strcmp(LOADER_TYPE_COMMON, ltype)) - __type = TYPE_COMMON; - else if (!strcmp(LOADER_TYPE_SW, ltype)) - __type = TYPE_SW; - else if (!strcmp(LOADER_TYPE_HW, ltype)) - __type = TYPE_HW; - - _D("Loader type:%d", __type); - - __preload_lib(extra); - - elm_init_cnt = elm_init(__argc, __argv); - _D("[candidate] elm init, returned: %d", elm_init_cnt); - setenv("AUL_LOADER_INIT", "1", 1); - - switch (__type) { - case TYPE_SW: - elm_config_accel_preference_set("none"); - setenv("AUL_HWACC", "none", 1); - __init_window(); - break; - - case TYPE_HW: - elm_config_accel_preference_set("hw"); - setenv("AUL_HWACC", "hw", 1); - __init_window(); - break; - - default: - __init_theme(); - break; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &__sys_hwacc); - if (ret != VCONF_OK) { - _E("Failed to get vconf int: %s", - VCONFKEY_SETAPPL_APP_HW_ACCELERATION); - } - - ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, - __vconf_cb, NULL); - if (ret != 0) { - _E("Failed to register callback for %s", - VCONFKEY_SETAPPL_APP_HW_ACCELERATION); - } -} - -static loader_convertible __converter_table[MAX_LOADER_TYPE][MAX_ACC_TYPE] = { - [TYPE_COMMON][SW_ACC] = NULL, - [TYPE_COMMON][HW_ACC] = NULL, - [TYPE_SW][SW_ACC] = NULL, - [TYPE_SW][HW_ACC] = __fini_window, - [TYPE_HW][SW_ACC] = __fini_window, - [TYPE_HW][HW_ACC] = NULL, -}; - -static int __loader_launch_cb(int argc, char **argv, const char *app_path, - const char *appid, const char *pkgid, const char *pkg_type, - void *user_data) -{ - const char *hwacc; - bundle *kb = launchpad_loader_get_bundle(); - int acc = SW_ACC; - loader_convertible convert; -#ifdef TIZEN_FEATURE_PRIORITY_CHANGE - const char *high_priority; -#endif - - elm_app_name_set(appid); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, - __vconf_cb); - if (kb == NULL) - return 0; - -#ifdef TIZEN_FEATURE_PRIORITY_CHANGE - high_priority = bundle_get_val(kb, AUL_K_HIGHPRIORITY); - if (high_priority) { - if (!strcmp(high_priority, "true")) - launchpad_loader_set_priority(-12); - bundle_del(kb, AUL_K_HIGHPRIORITY); - } -#endif - - hwacc = bundle_get_val(kb, AUL_K_HWACC); - - if (!hwacc) - return 0; - - if (strcmp(hwacc, "USE") == 0 || - (strcmp(hwacc, "SYS") == 0 && - __sys_hwacc == SETTING_HW_ACCELERATION_ON)) { - acc = HW_ACC; - } - - convert = __converter_table[__type][acc]; - if (convert) - convert(); - - return 0; -} - -static int __loader_terminate_cb(int argc, char **argv, void *user_data) -{ - void *handle; - int (*dl_main)(int, char **); - char err_str[MAX_LOCAL_BUFSZ]; - char old_cwd[PATH_MAX]; - bool restore = false; - char *libdir = NULL; - char hwc_message[MAX_LOCAL_BUFSZ]; - - SECURE_LOGD("[candidate] Launch real application (%s)", - argv[LOADER_ARG_PATH]); - - if (getcwd(old_cwd, sizeof(old_cwd)) == NULL) { - _E("getcwd() is failed"); - goto do_dlopen; - } - - libdir = _get_libdir(argv[LOADER_ARG_PATH]); - if (libdir == NULL) - goto do_dlopen; - - /* 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. - */ - if (chdir(libdir)) - _E("failed to chdir: %d", errno); - else - restore = true; - -do_dlopen: - snprintf(hwc_message, sizeof(hwc_message), "%d|lib loading start", getpid()); - prctl(PR_TASK_PERF_USER_TRACE, hwc_message, strlen(hwc_message)); - _W("dlopen(%s) ++", argv[LOADER_ARG_PATH]); - handle = dlopen(argv[LOADER_ARG_PATH], - RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE); - _W("dlopen(%s) --", argv[LOADER_ARG_PATH]); - if (handle == NULL) { - _E("dlopen(%s) is failed. error(%s)", - argv[LOADER_ARG_PATH], dlerror()); - goto do_exec; - } - - snprintf(hwc_message, sizeof(hwc_message), "%d|lib loading end", getpid()); - prctl(PR_TASK_PERF_USER_TRACE, hwc_message, strlen(hwc_message)); - dlerror(); - - if (restore && chdir(old_cwd)) - _E("failed to chdir: %d", errno); - - dl_main = dlsym(handle, "main"); - if (dl_main == NULL) { - _E("dlsym not founded(%s). Please export 'main' function", - dlerror()); - dlclose(handle); - goto do_exec; - } - - free(libdir); - return dl_main(argc, argv); - -do_exec: - 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) - setenv("LD_LIBRARY_PATH", libdir, 1); - free(libdir); - 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); - } - } - - return 0; -} - -static Eina_Bool __process_fd_handler(void *data, Ecore_Fd_Handler *handler) -{ - int fd; - - fd = ecore_main_fd_handler_fd_get(handler); - if (fd == -1) { - _D("[candidate] ECORE_FD_GET"); - exit(-1); - } - - if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) { - if (__receiver) - __receiver(fd); - } else if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR)) { - _D("[candidate] ECORE_FD_ERROR"); - close(fd); - exit(-1); - } - - return ECORE_CALLBACK_CANCEL; -} - -static void __adapter_loop_begin(void *user_data) -{ - ecore_main_loop_begin(); -} - -static void __adapter_loop_quit(void *user_data) -{ - ecore_main_loop_quit(); -} - -static void __adapter_add_fd(void *user_data, int fd, - loader_receiver_cb receiver) -{ - __fd_handler = ecore_main_fd_handler_add(fd, - ECORE_FD_READ | ECORE_FD_ERROR, __process_fd_handler, - NULL, NULL, NULL); - if (__fd_handler == NULL) { - _D("fd_handler is NULL"); - close(fd); - exit(-1); - } - - __receiver = receiver; -} - -static void __adapter_remove_fd(void *user_data, int fd) -{ - if (__fd_handler) { - ecore_main_fd_handler_del(__fd_handler); - __fd_handler = NULL; - __receiver = NULL; - } -} - -int main(int argc, char **argv) -{ - loader_lifecycle_callback_s callbacks = { - .create = __loader_create_cb, - .launch = __loader_launch_cb, - .terminate = __loader_terminate_cb - }; - - loader_adapter_s adapter = { - .loop_begin = __adapter_loop_begin, - .loop_quit = __adapter_loop_quit, - .add_fd = __adapter_add_fd, - .remove_fd = __adapter_remove_fd - }; - - __argc = argc; - __argv = argv; - - return launchpad_loader_main(argc, argv, &callbacks, &adapter, NULL); -} diff --git a/src/launchpad-process-pool/app_executor.cc b/src/launchpad-process-pool/app_executor.cc index cd58dde..f534aef 100644 --- a/src/launchpad-process-pool/app_executor.cc +++ b/src/launchpad-process-pool/app_executor.cc @@ -32,13 +32,13 @@ #include #include #include +#include #include #include "launchpad-process-pool/config.hh" #include "launchpad-process-pool/debug.hh" #include "launchpad-process-pool/log_private.hh" #include "launchpad-process-pool/signal_manager.hh" -#include "launchpad-process-pool/user_tracer.hh" namespace launchpad { namespace fs = std::filesystem; @@ -139,7 +139,7 @@ void AppExecutor::OnExecution() { SECURE_LOGD("input argument %d : %s##", i, app_argv[i]); } - auto lib_dir = Util::GetLibDirectory(app_info_); + auto lib_dir = Util::GetLibDirectory(app_info_->GetAppPath()); if (!lib_dir.empty()) setenv("LD_LIBRARY_PATH", lib_dir.c_str(), 1); diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 8a24ddd..8ff9fe7 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "launchpad-process-pool/config.hh" @@ -48,7 +49,6 @@ #include "launchpad-process-pool/memory_monitor.hh" #include "launchpad-process-pool/signal_manager.hh" #include "launchpad-process-pool/tracer.hh" -#include "launchpad-process-pool/user_tracer.hh" #include "launchpad-process-pool/util.hh" #include "launchpad-process-pool/worker.hh" diff --git a/src/launchpad-process-pool/loader_context.cc b/src/launchpad-process-pool/loader_context.cc index fbb8ddf..cb30f51 100644 --- a/src/launchpad-process-pool/loader_context.cc +++ b/src/launchpad-process-pool/loader_context.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,6 @@ #include "launchpad-process-pool/log.hh" #include "launchpad-process-pool/log_private.hh" #include "launchpad-process-pool/memory_monitor.hh" -#include "launchpad-process-pool/user_tracer.hh" #include "launchpad-process-pool/util.hh" namespace fs = std::filesystem; diff --git a/src/launchpad-process-pool/loader_factory.cc b/src/launchpad-process-pool/loader_factory.cc index c52524f..e62b8c3 100644 --- a/src/launchpad-process-pool/loader_factory.cc +++ b/src/launchpad-process-pool/loader_factory.cc @@ -20,12 +20,12 @@ #include #include +#include #include #include "launchpad-process-pool/hydra_loader_context.hh" #include "launchpad-process-pool/loader_context.hh" #include "launchpad-process-pool/log_private.hh" -#include "launchpad-process-pool/user_tracer.hh" namespace launchpad { namespace { diff --git a/src/launchpad-process-pool/loader_manager.hh b/src/launchpad-process-pool/loader_manager.hh index 028e617..31e4ba0 100644 --- a/src/launchpad-process-pool/loader_manager.hh +++ b/src/launchpad-process-pool/loader_manager.hh @@ -26,9 +26,10 @@ #include #include +#include + #include "launchpad-process-pool/app_defined_loader_info_manager.hh" #include "launchpad-process-pool/app_labels_monitor.hh" -#include "launchpad-process-pool/hw_acceleration_config.hh" #include "launchpad-process-pool/hydra_loader_context.hh" #include "launchpad-process-pool/loader_context.hh" #include "launchpad-process-pool/loader_info.hh" diff --git a/src/launchpad-process-pool/user_tracer.cc b/src/lib/launchpad-common/user_tracer.cc similarity index 95% rename from src/launchpad-process-pool/user_tracer.cc rename to src/lib/launchpad-common/user_tracer.cc index 5a94c0f..d278758 100644 --- a/src/launchpad-process-pool/user_tracer.cc +++ b/src/lib/launchpad-common/user_tracer.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "launchpad-process-pool/user_tracer.hh" +#include "launchpad-common/user_tracer.hh" #include diff --git a/src/launchpad-process-pool/user_tracer.hh b/src/lib/launchpad-common/user_tracer.hh similarity index 85% rename from src/launchpad-process-pool/user_tracer.hh rename to src/lib/launchpad-common/user_tracer.hh index da18bda..919dbc8 100644 --- a/src/launchpad-process-pool/user_tracer.hh +++ b/src/lib/launchpad-common/user_tracer.hh @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef LAUNCHPAD_PROCESS_POOL_USER_TRACER_HH_ -#define LAUNCHPAD_PROCESS_POOL_USER_TRACER_HH_ +#ifndef LAUNCHPAD_COMMON_USER_TRACER_HH_ +#define LAUNCHPAD_COMMON_USER_TRACER_HH_ #include @@ -34,4 +34,4 @@ class UserTracer { } // namespace launchpad -#endif // LAUNCHPAD_PROCESS_POOL_USER_TRACER_HH_ +#endif // LAUNCHPAD_COMMON_USER_TRACER_HH_ diff --git a/src/launchpad-process-pool/hw_acceleration_config.cc b/src/lib/launchpad-glib/hw_acceleration_config.cc similarity index 91% rename from src/launchpad-process-pool/hw_acceleration_config.cc rename to src/lib/launchpad-glib/hw_acceleration_config.cc index c993bca..24c1ab3 100644 --- a/src/launchpad-process-pool/hw_acceleration_config.cc +++ b/src/lib/launchpad-glib/hw_acceleration_config.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "launchpad-process-pool/hw_acceleration_config.hh" +#include "launchpad-glib/hw_acceleration_config.hh" -#include "launchpad-process-pool/log_private.hh" +#include "launchpad-glib/log_private.hh" namespace launchpad { diff --git a/src/launchpad-process-pool/hw_acceleration_config.hh b/src/lib/launchpad-glib/hw_acceleration_config.hh similarity index 83% rename from src/launchpad-process-pool/hw_acceleration_config.hh rename to src/lib/launchpad-glib/hw_acceleration_config.hh index 3f9d209..9c2e293 100644 --- a/src/launchpad-process-pool/hw_acceleration_config.hh +++ b/src/lib/launchpad-glib/hw_acceleration_config.hh @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef LAUNCHPAD_PROCESS_POOL_HW_ACCELERATION_CONFIG_HH_ -#define LAUNCHPAD_PROCESS_POOL_HW_ACCELERATION_CONFIG_HH_ +#ifndef LAUNCHPAD_GLIB_HW_ACCELERATION_CONFIG_HH_ +#define LAUNCHPAD_GLIB_HW_ACCELERATION_CONFIG_HH_ #include @@ -37,4 +37,4 @@ class HWAccelerationConfig : public Vconf::IEvent { } // namespace launchpad -#endif // LAUNCHPAD_PROCESS_POOL_HW_ACCELERATION_CONFIG_HH_ +#endif // LAUNCHPAD_GLIB_HW_ACCELERATION_CONFIG_HH_ diff --git a/src/lib/launchpad-glib/util.cc b/src/lib/launchpad-glib/util.cc index 1ba7970..12745e1 100644 --- a/src/lib/launchpad-glib/util.cc +++ b/src/lib/launchpad-glib/util.cc @@ -453,8 +453,8 @@ int Util::WaitTepMount(const AppInfo* app_info) { return 0; } -std::string Util::GetLibDirectory(const AppInfo* app_info) { - std::filesystem::path path(app_info->GetAppPath()); +std::string Util::GetLibDirectory(const std::string& app_path) { + std::filesystem::path path(app_path); auto lib_dir = path.parent_path().string() + "/../lib/"; if (std::filesystem::exists(lib_dir)) return lib_dir; diff --git a/src/lib/launchpad-glib/util.hh b/src/lib/launchpad-glib/util.hh index d1646c0..9dfeaff 100644 --- a/src/lib/launchpad-glib/util.hh +++ b/src/lib/launchpad-glib/util.hh @@ -40,7 +40,7 @@ class EXPORT_API Util { static int EnableExternalPackage(const AppInfo* app_info); static int MountResourceDirectories(const AppInfo* app_info); static int WaitTepMount(const AppInfo* app_info); - static std::string GetLibDirectory(const AppInfo* app_info); + static std::string GetLibDirectory(const std::string& app_path); static void CloseAllFds(); static int PrepareAppSocket(); static int PrepareAppIdFile(const AppInfo* app_info); -- 2.7.4 From 3a9a2dda6726402a4df2acd9a7f572b77862aa47 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 19 Jun 2023 17:08:11 +0900 Subject: [PATCH 15/16] Release version 0.34.0 Changes: - Add status to AUL_DBUS_APPDEAD_SIGNAL - Modify app-defined-loader - Refactor launchpad loader Change-Id: I6e4a75a8d68d45bca046ad214a7876128cfe0200 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 7b0c8b9..63da262 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.33.7 +Version: 0.34.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From e9c3e389212dfee8a3074b518979174d50950ecf Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 20 Jun 2023 09:21:00 +0900 Subject: [PATCH 16/16] Fix build error In 64bit build system, uint64_t is mapped to unsigned long int. Therefore, when printing uint64_t, it should be cast as unsigned long long. Logs: [ 209s] /home/abuild/rpmbuild/BUILD/launchpad-0.34.0/src/app-defined-loader/app-defined-loader.cc: In member function 'void launchpad::loader::AppDefinedLoader::PreloadLib(tizen_base::Bundle)': [ 209s] /usr/include/dlog/dlog-internal.h:72:31: error: format '%llu' expects argument of type 'long long unsigned int', but argument 8 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=] Change-Id: Ia59a6f765d70040037a031a0715a7622166e19fb Signed-off-by: Changgyu Choi --- src/app-defined-loader/app-defined-loader.cc | 4 +++- src/launchpad-loader/launchpad_loader.cc | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app-defined-loader/app-defined-loader.cc b/src/app-defined-loader/app-defined-loader.cc index cfef14a..8d621e1 100644 --- a/src/app-defined-loader/app-defined-loader.cc +++ b/src/app-defined-loader/app-defined-loader.cc @@ -123,7 +123,9 @@ class AppDefinedLoader { uint64_t pss; launchpad::Procfs::GetPssMemory(getpid(), &pss); if (pss > threshold_) { - _W("Pss(%llu) is over threshold(%llu)", pss, threshold_); + _W("Pss(%llu) is over threshold(%llu)", + static_cast(pss), + static_cast(threshold_)); break; } } diff --git a/src/launchpad-loader/launchpad_loader.cc b/src/launchpad-loader/launchpad_loader.cc index 43a95c7..24981c0 100644 --- a/src/launchpad-loader/launchpad_loader.cc +++ b/src/launchpad-loader/launchpad_loader.cc @@ -41,7 +41,7 @@ void PreloadLibraries(const tizen_base::Bundle& extra) { uint64_t mem_pss; launchpad::Procfs::GetPssMemory(getpid(), &mem_pss); - _W("PSS: %llu kB", mem_pss); + _W("PSS: %llu kB", static_cast(mem_pss)); for (auto& lib : libs) { if (lib.empty()) continue; @@ -53,7 +53,8 @@ void PreloadLibraries(const tizen_base::Bundle& extra) { } launchpad::Procfs::GetPssMemory(getpid(), &mem_pss); - _W("Preload %s# - handle: %p, PSS: %llu kB", lib.c_str(), handle, mem_pss); + _W("Preload %s# - handle: %p, PSS: %llu kB", lib.c_str(), handle, + static_cast(mem_pss)); } } -- 2.7.4