From 3ad292025c022dac2139e5a33debf850df27a9af Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Thu, 27 Feb 2020 20:46:27 +0000 Subject: [PATCH 1/2] Reset post_data_ and services_update_finished_ on userspace reboot Test: adb reboot userspace Bug: 143970043 Change-Id: I77d47a8460b1526337a318547a59141334e11cdd --- init/reboot.cpp | 1 + init/service_list.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/init/reboot.cpp b/init/reboot.cpp index f7bdf16ef..cad192de9 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -820,6 +820,7 @@ static Result DoUserspaceReboot() { LOG(INFO) << "Re-enabling service '" << s->name() << "'"; s->Enable(); } + ServiceList::GetInstance().ResetState(); LeaveShutdown(); ActionManager::GetInstance().QueueEventTrigger("userspace-reboot-resume"); guard.Disable(); // Go on with userspace reboot. diff --git a/init/service_list.h b/init/service_list.h index 8cbc87888..280a2280f 100644 --- a/init/service_list.h +++ b/init/service_list.h @@ -81,6 +81,11 @@ class ServiceList { bool IsServicesUpdated() const { return services_update_finished_; } void DelayService(const Service& service) REQUIRES(service_lock); + void ResetState() { + post_data_ = false; + services_update_finished_ = false; + } + private: std::vector> services_; From 6963f81a2b9d07d266b768aa03cfd212bf64b107 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Fri, 28 Feb 2020 11:37:22 +0000 Subject: [PATCH 2/2] Stop & Resume property service when switching to bootstrap namespace Test: atest CtsUserspaceRebootHostSideTestCases Bug: 149745936 Change-Id: I9d30b75f4b4177175ce086c3b6a7c0bba9a17396 --- init/mount_namespace.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/init/mount_namespace.cpp b/init/mount_namespace.cpp index aa368492d..21750754e 100644 --- a/init/mount_namespace.cpp +++ b/init/mount_namespace.cpp @@ -323,10 +323,20 @@ bool SwitchToBootstrapMountNamespaceIfNeeded() { } if (bootstrap_ns_id != GetMountNamespaceId() && bootstrap_ns_fd.get() != -1 && IsApexUpdatable()) { + // The property service thread and its descendent threads must be in the correct mount + // namespace to call Service::Start(), however setns() only operates on a single thread and + // fails when secondary threads attempt to join the same mount namespace. Therefore, we + // must join the property service thread and its descendents before the setns() call. Those + // threads are then started again after the setns() call, and they'll be in the proper + // namespace. + PausePropertyService(); + if (setns(bootstrap_ns_fd.get(), CLONE_NEWNS) == -1) { PLOG(ERROR) << "Failed to switch to bootstrap mount namespace."; return false; } + + ResumePropertyService(); } return true; }