From 55598ec9cc0078184699305a98f3739f268d4d7b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 27 Apr 2023 23:43:39 +0000 Subject: [PATCH] Dispose candidate process of process pool When the app label changed event is received, the launchpad has to terminate all candidate processes. If it's not, calling the security_manager_prepare_app2() will be failed when executing an application. Change-Id: I730bfc0fa5126743d2bd80c541d131ae581ad931 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/loader_executor.cc | 5 +++++ src/launchpad-process-pool/loader_executor.hh | 1 + src/launchpad-process-pool/loader_manager.cc | 3 +++ src/launchpad-process-pool/process_pool.cc | 24 +++++++++++++++++++----- src/launchpad-process-pool/process_pool.hh | 5 +++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/launchpad-process-pool/loader_executor.cc b/src/launchpad-process-pool/loader_executor.cc index 1be888e..7184d99 100644 --- a/src/launchpad-process-pool/loader_executor.cc +++ b/src/launchpad-process-pool/loader_executor.cc @@ -73,6 +73,11 @@ bool LoaderExecutor::HasCandidateProcess() const { return process_pool_->IsPrepared(); } +void LoaderExecutor::DisposeCandidateProcess() { + process_pool_->Dispose(); + process_pool_->SetTimer(); +} + void LoaderExecutor::OnExecution() { std::vector loader_argv(loader_argv_.size() + 1); int loader_argc = loader_argv_.size(); diff --git a/src/launchpad-process-pool/loader_executor.hh b/src/launchpad-process-pool/loader_executor.hh index a55ca30..c3b2664 100644 --- a/src/launchpad-process-pool/loader_executor.hh +++ b/src/launchpad-process-pool/loader_executor.hh @@ -40,6 +40,7 @@ class LoaderExecutor : public Executor::Delegator, pid_t Execute(const LoaderContext* loader_context, int priority); bool HasCandidateProcess() const; + void DisposeCandidateProcess(); private: LoaderExecutor(); diff --git a/src/launchpad-process-pool/loader_manager.cc b/src/launchpad-process-pool/loader_manager.cc index 7d88860..46620ef 100644 --- a/src/launchpad-process-pool/loader_manager.cc +++ b/src/launchpad-process-pool/loader_manager.cc @@ -20,6 +20,7 @@ #include #include "launchpad-process-pool/config.hh" +#include "launchpad-process-pool/loader_executor.hh" #include "launchpad-process-pool/loader_factory.hh" #include "launchpad-process-pool/log_private.hh" @@ -457,6 +458,8 @@ void LoaderManager::OnAppLabelsChanged() { context->Prepare(); } } + + LoaderExecutor::GetInst().DisposeCandidateProcess(); } void LoaderManager::OnMemoryStatusChanged(bool low_memory, diff --git a/src/launchpad-process-pool/process_pool.cc b/src/launchpad-process-pool/process_pool.cc index cec1c39..19fbcc6 100644 --- a/src/launchpad-process-pool/process_pool.cc +++ b/src/launchpad-process-pool/process_pool.cc @@ -40,11 +40,7 @@ ProcessPool::ProcessPool(int num_processes, IEvent* event_listener = nullptr) } ProcessPool::~ProcessPool() { - while (!queue_.empty()) { - auto process = std::move(queue_.front()); - queue_.pop(); - process->Kill(); - } + Dispose(); } bool ProcessPool::IsPrepared() const { @@ -62,6 +58,17 @@ pid_t ProcessPool::Execute(std::shared_ptr app_packet) { return process->GetPid(); } +void ProcessPool::Dispose() { + while (!queue_.empty()) { + auto process = std::move(queue_.front()); + queue_.pop(); + process->Kill(); + _D("Kill process(%d)", process->GetPid()); + } + + UnsetTimer(); +} + ProcessPool::Process::Process(pid_t pid, int fd) : pid_(pid), socket_(new Socket(fd)) { } @@ -162,6 +169,13 @@ void ProcessPool::SetTimer() { timer_ = g_timeout_add(1000, OnTimeout, this); } +void ProcessPool::UnsetTimer() { + if (timer_ != 0) { + g_source_remove(timer_); + timer_ = 0; + } +} + gboolean ProcessPool::OnTimeout(gpointer user_data) { auto* process_pool = static_cast(user_data); process_pool->PrepareProcess(); diff --git a/src/launchpad-process-pool/process_pool.hh b/src/launchpad-process-pool/process_pool.hh index 302a826..85b87fa 100644 --- a/src/launchpad-process-pool/process_pool.hh +++ b/src/launchpad-process-pool/process_pool.hh @@ -45,6 +45,8 @@ class ProcessPool : public Executor::Delegator, bool IsPrepared() const; pid_t Execute(std::shared_ptr app_packet); + void Dispose(); + void SetTimer(); private: class Process { @@ -61,10 +63,9 @@ class ProcessPool : public Executor::Delegator, }; void OnExecution() override; - + void UnsetTimer(); void PrepareProcess(); int WaitForRequest(std::unique_ptr socket); - void SetTimer(); static gboolean OnTimeout(gpointer user_data); private: -- 2.7.4