Modify launch request handling 50/293050/3
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 19 May 2023 01:03:57 +0000 (01:03 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 19 May 2023 03:20:57 +0000 (03:20 +0000)
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 <h.jhun@samsung.com>
src/launchpad-process-pool/launchpad.cc
src/launchpad-process-pool/launchpad.hh
src/launchpad-process-pool/loader_context.cc
src/launchpad-process-pool/loader_context.hh
src/launchpad-process-pool/loader_manager.cc
src/launchpad-process-pool/loader_manager.hh

index bd5517c..3fdb624 100644 (file)
@@ -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<LoaderContext>& 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<HydraLoaderContext*>(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) {
index 4a33a10..477a40f 100644 (file)
@@ -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_;
index 13d7b22..a0cc855 100644 (file)
@@ -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();
   }
index 0ab3bae..8559ebe 100644 (file)
@@ -62,6 +62,7 @@ class LoaderContext : public std::enable_shared_from_this<LoaderContext>,
    public:
     virtual ~IEvent() = default;
     virtual void OnTimeoutEvent(LoaderContext* context) = 0;
+    virtual void OnLoaderLaunched(LoaderContext* context) = 0;
     virtual void OnLoaderPrepared(LoaderContext* context) = 0;
   };
 
index 549b7ab..ee3b86a 100644 (file)
@@ -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
index cf8aa4a..028e617 100644 (file)
@@ -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;