From 646e001bb5e232f38a79cc5ac3d9b4ed9c74ac65 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Mon, 21 Aug 2023 17:34:37 +0900 Subject: [PATCH] init: clean up DelayService() ServiceList's services_update_finished flag was overlapped with the global flag: is_default_mount_namespace_ready. Now DelayService() relies on the is_default_mount_namespace_ready flag. Add a service description with 'updatable' flag and invoke 'start ' in 'on init' block (which comes before APEX activation). See the log for "Cannot start an updatable service". Bug: 293535323 Test: see the comment Change-Id: I9341ba1a95d9b3b7c6081b530850d61f105f0a56 --- init/builtins.cpp | 3 +-- init/service.cpp | 4 ++-- init/service_list.cpp | 7 ++----- init/service_list.h | 9 ++------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/init/builtins.cpp b/init/builtins.cpp index a5b762cbb..7715424f5 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -1304,8 +1304,7 @@ static Result do_perform_apex_config(const BuiltinArguments& args) { } if (!bootstrap) { - // Now start delayed services - ServiceList::GetInstance().MarkServicesUpdate(); + ServiceList::GetInstance().StartDelayedServices(); } return {}; } diff --git a/init/service.cpp b/init/service.cpp index a0b3478c0..5e900ee4d 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -420,7 +420,7 @@ Result Service::ExecStart() { } }); - if (is_updatable() && !ServiceList::GetInstance().IsServicesUpdated()) { + if (is_updatable() && !IsDefaultMountNamespaceReady()) { // Don't delay the service for ExecStart() as the semantic is that // the caller might depend on the side effect of the execution. return Error() << "Cannot start an updatable service '" << name_ @@ -581,7 +581,7 @@ Result Service::Start() { } }); - if (is_updatable() && !ServiceList::GetInstance().IsServicesUpdated()) { + if (is_updatable() && !IsDefaultMountNamespaceReady()) { ServiceList::GetInstance().DelayService(*this); return Error() << "Cannot start an updatable service '" << name_ << "' before configs from APEXes are all loaded. " diff --git a/init/service_list.cpp b/init/service_list.cpp index 937d82e20..1c56e8a59 100644 --- a/init/service_list.cpp +++ b/init/service_list.cpp @@ -76,10 +76,7 @@ bool ServiceList::IsPostData() { return post_data_; } -void ServiceList::MarkServicesUpdate() { - services_update_finished_ = true; - - // start the delayed services +void ServiceList::StartDelayedServices() { for (const auto& name : delayed_service_names_) { Service* service = FindService(name); if (service == nullptr) { @@ -94,7 +91,7 @@ void ServiceList::MarkServicesUpdate() { } void ServiceList::DelayService(const Service& service) { - if (services_update_finished_) { + if (IsDefaultMountNamespaceReady()) { LOG(ERROR) << "Cannot delay the start of service '" << service.name() << "' because all services are already updated. Ignoring."; return; diff --git a/init/service_list.h b/init/service_list.h index f858bc370..44e84535c 100644 --- a/init/service_list.h +++ b/init/service_list.h @@ -85,14 +85,10 @@ class ServiceList { void MarkPostData(); bool IsPostData(); - void MarkServicesUpdate(); - bool IsServicesUpdated() const { return services_update_finished_; } void DelayService(const Service& service); + void StartDelayedServices(); - void ResetState() { - post_data_ = false; - services_update_finished_ = false; - } + void ResetState() { post_data_ = false; } auto size() const { return services_.size(); } @@ -100,7 +96,6 @@ class ServiceList { std::vector> services_; bool post_data_ = false; - bool services_update_finished_ = false; std::vector delayed_service_names_; };