auto* socket = new ServerSocket();
const std::string endpoint = kRunAulDaemonsPath + std::to_string(getuid()) +
- kLaunchpadProcessPoolSock;
+ "/" + kLaunchpadProcessPoolSock;
socket->Bind(endpoint);
socket->SetReceiveBufferSize(kReceivedBufferSize);
socket->Listen(kMaxPendingConnection);
}
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) {
auto* hydra_loader_context = dynamic_cast<HydraLoaderContext*>(context);
if (hydra_loader_context != nullptr)
hydra_loader_context->Prepare();
- else
- context->Prepare();
}
} // namespace
_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;
}
}
}
+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) {
void LoaderContext::SetPid(pid_t pid) {
pid_ = pid;
+ if (pid_ > 0) {
+ if (listener_ != nullptr)
+ listener_->OnLoaderLaunched(this);
+ }
}
pid_t LoaderContext::GetCallerPid() const {
client_channel_->SetCloseOnDestroy(false);
if (IsHydraMode())
- pid_ = peer_cred->GetPid();
+ SetPid(peer_cred->GetPid());
prepared_ = true;
if (listener_ != nullptr)
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();
}