Stop & Resume property service when switching to bootstrap namespace

Test: atest CtsUserspaceRebootHostSideTestCases
Bug: 148236233
Bug: 149745936
Merged-In: I9d30b75f4b4177175ce086c3b6a7c0bba9a17396
Change-Id: I9d30b75f4b4177175ce086c3b6a7c0bba9a17396
(cherry picked from commit 6963f81a2b)
This commit is contained in:
Nikita Ioffe 2020-02-28 11:37:22 +00:00 committed by Tom Cherry
parent d2dab830d3
commit 352ae2d225

View file

@ -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;
}