From: Hwankyu Jhun Date: Fri, 19 May 2023 01:03:57 +0000 (+0000) Subject: Modify launch request handling X-Git-Tag: accepted/tizen/unified/20230601.162952~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F50%2F293050%2F3;p=platform%2Fcore%2Fappfw%2Flaunchpad.git Modify launch request handling If the loader context is not prepared, the launchpad does not wait for the loader is ready. Even if it's not prepared, the launchpad wait until the loader is ready when the loader is hydra mode. And, When setting the process ID of the loader context, the launchpad sends the result to the caller if it is pending. Change-Id: I35674ab5727644cacf3e3770e252e4a2a462c9f0 Signed-off-by: Hwankyu Jhun --- diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index bd5517c..3fdb624 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -117,7 +117,7 @@ ServerSocket* GetLaunchpadSocket() { auto* socket = new ServerSocket(); const std::string endpoint = kRunAulDaemonsPath + std::to_string(getuid()) + - kLaunchpadProcessPoolSock; + "/" + kLaunchpadProcessPoolSock; socket->Bind(endpoint); socket->SetReceiveBufferSize(kReceivedBufferSize); socket->Listen(kMaxPendingConnection); @@ -157,8 +157,8 @@ int GetLoaderIdFromBundle(const tizen_base::Bundle& b) { } inline bool CanUseLoaderContext(const std::shared_ptr& context) { - return ((LoaderExecutor::GetInst().HasCandidateProcess() || - context->GetPid() > 0) && !context->IsPending()); + return (context->IsHydraMode() || context->GetPid() > 0) && + !context->IsPending(); } inline void CheckAndPrepareLoaderContext(LoaderContext* context) { @@ -168,8 +168,6 @@ inline void CheckAndPrepareLoaderContext(LoaderContext* context) { auto* hydra_loader_context = dynamic_cast(context); if (hydra_loader_context != nullptr) hydra_loader_context->Prepare(); - else - context->Prepare(); } } // namespace @@ -481,9 +479,12 @@ Launchpad::LaunchResult Launchpad::LaunchRequestDo( _W("Loader context is not prepared"); loader_context->SetPending(true); CheckAndPrepareLoaderContext(loader_context.get()); - CPUBoostController::DoBoost(loader_context->GetPid(), - CPUBoostController::Level::Strong, 10000); - request->SendResult(loader_context->GetPid()); + if (loader_context->GetPid() > 0) { + CPUBoostController::DoBoost(loader_context->GetPid(), + CPUBoostController::Level::Strong, 10000); + request->SendResult(loader_context->GetPid()); + } + pending_requests_.push_back(std::move(request)); return LaunchResult::Pending; } @@ -596,6 +597,21 @@ void Launchpad::OnLoaderPrepared(LoaderContext* loader_context) { } } +void Launchpad::OnLoaderLaunched(LoaderContext* loader_context) { + _W("Loader is prepared. name(%s), pid(%d)", + loader_context->GetLoaderName().c_str(), loader_context->GetPid()); + if (!loader_context->IsPending()) + return; + + for (auto& request : pending_requests_) { + auto context = request->GetAvailableLoaderContext(); + if (context != nullptr && context.get() == loader_context) { + request->SendResult(loader_context->GetPid()); + return; + } + } +} + } // namespace launchpad int main(int argc, char** argv) { diff --git a/src/launchpad-process-pool/launchpad.hh b/src/launchpad-process-pool/launchpad.hh index 4a33a10..477a40f 100644 --- a/src/launchpad-process-pool/launchpad.hh +++ b/src/launchpad-process-pool/launchpad.hh @@ -82,7 +82,8 @@ class Launchpad : public IOChannel::IEvent, void OnIOEventReceived(int fd, int condition) override; void OnSigchldReceived(pid_t pid) override; - void OnLoaderPrepared(LoaderContext* loader_context); + void OnLoaderPrepared(LoaderContext* loader_context) override; + void OnLoaderLaunched(LoaderContext* loader_context) override; private: int argc_; diff --git a/src/launchpad-process-pool/loader_context.cc b/src/launchpad-process-pool/loader_context.cc index 13d7b22..a0cc855 100644 --- a/src/launchpad-process-pool/loader_context.cc +++ b/src/launchpad-process-pool/loader_context.cc @@ -289,6 +289,10 @@ pid_t LoaderContext::GetPid() const { void LoaderContext::SetPid(pid_t pid) { pid_ = pid; + if (pid_ > 0) { + if (listener_ != nullptr) + listener_->OnLoaderLaunched(this); + } } pid_t LoaderContext::GetCallerPid() const { @@ -609,7 +613,7 @@ void LoaderContext::HandleLoaderEvent() { client_channel_->SetCloseOnDestroy(false); if (IsHydraMode()) - pid_ = peer_cred->GetPid(); + SetPid(peer_cred->GetPid()); prepared_ = true; if (listener_ != nullptr) @@ -632,7 +636,7 @@ void LoaderContext::HandleLoaderClientEvent(int condition) { if (condition & (IOChannel::IOCondition::IO_HUP | IOChannel::IOCondition::IO_NVAL)) { SECURE_LOGE("Type %d loader was disconnected. pid: %d", GetType(), pid_); - pid_ = 0; + SetPid(0); Dispose(); Prepare(); } diff --git a/src/launchpad-process-pool/loader_context.hh b/src/launchpad-process-pool/loader_context.hh index 0ab3bae..8559ebe 100644 --- a/src/launchpad-process-pool/loader_context.hh +++ b/src/launchpad-process-pool/loader_context.hh @@ -62,6 +62,7 @@ class LoaderContext : public std::enable_shared_from_this, public: virtual ~IEvent() = default; virtual void OnTimeoutEvent(LoaderContext* context) = 0; + virtual void OnLoaderLaunched(LoaderContext* context) = 0; virtual void OnLoaderPrepared(LoaderContext* context) = 0; }; diff --git a/src/launchpad-process-pool/loader_manager.cc b/src/launchpad-process-pool/loader_manager.cc index 549b7ab..ee3b86a 100644 --- a/src/launchpad-process-pool/loader_manager.cc +++ b/src/launchpad-process-pool/loader_manager.cc @@ -530,4 +530,9 @@ void LoaderManager::OnLoaderPrepared(LoaderContext* context) { event_listener_->OnLoaderPrepared(context); } +void LoaderManager::OnLoaderLaunched(LoaderContext* context) { + if (event_listener_ != nullptr) + event_listener_->OnLoaderLaunched(context); +} + } // namespace launchpad diff --git a/src/launchpad-process-pool/loader_manager.hh b/src/launchpad-process-pool/loader_manager.hh index cf8aa4a..028e617 100644 --- a/src/launchpad-process-pool/loader_manager.hh +++ b/src/launchpad-process-pool/loader_manager.hh @@ -46,6 +46,7 @@ class LoaderManager : public AppDefinedLoaderInfoManager::IEvent, class IEvent { public: virtual ~IEvent() = default; + virtual void OnLoaderLaunched(LoaderContext* context) = 0; virtual void OnLoaderPrepared(LoaderContext* context) = 0; }; @@ -105,6 +106,7 @@ class LoaderManager : public AppDefinedLoaderInfoManager::IEvent, bool OnIdleCheck(LoaderContext* context) override; void OnLoaderLaunch(LoaderContext* context) override; void OnLoaderPrepared(LoaderContext* context) override; + void OnLoaderLaunched(LoaderContext* context) override; private: bool disposed_ = true;