summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiakai Zhang <jiakaiz@google.com>2024-05-14 14:55:59 +0000
committerTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-05-14 17:22:04 +0000
commit0e759267235d7ae4ff63e65fddc06dc85ca506aa (patch)
tree080d8d925c3e81ddcacfe245c341b5e6bf56f8b2
parent31778a493a96b4382acff11b33a8c624d4f52045 (diff)
downloadart-0e759267235d7ae4ff63e65fddc06dc85ca506aa.tar.gz
Don't run apexd in teardown if there is no apex.
If setup fails in the middle of mounting filesystems, it's possible that /system/bin/apexd exists but cannot be run (e.g., because /sys and /proc are not mounted yet). Running apexd in this case results in a crash, which is expected but can easily become a red-herring. Bug: 311377497 Change-Id: Iaf8a201dd2dcbb8f17ae2ab16b285eac962c6ce4 Test: Presubmit
-rw-r--r--dexopt_chroot_setup/dexopt_chroot_setup.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/dexopt_chroot_setup/dexopt_chroot_setup.cc b/dexopt_chroot_setup/dexopt_chroot_setup.cc
index f7d1ea4d37..5c4d4ea151 100644
--- a/dexopt_chroot_setup/dexopt_chroot_setup.cc
+++ b/dexopt_chroot_setup/dexopt_chroot_setup.cc
@@ -431,22 +431,24 @@ Result<void> DexoptChrootSetup::SetUpChroot(const std::optional<std::string>& ot
}
Result<void> DexoptChrootSetup::TearDownChroot() const {
- if (OS::FileExists(PathInChroot("/system/bin/apexd").c_str())) {
+ std::vector<FstabEntry> apex_entries =
+ OR_RETURN(GetProcMountsDescendantsOfPath(PathInChroot("/apex")));
+ // If there is only one entry, it's /apex itself.
+ bool has_apex = apex_entries.size() > 1;
+
+ if (has_apex && OS::FileExists(PathInChroot("/system/bin/apexd").c_str())) {
+ // Delegate to apexd to unmount all APEXes. It also cleans up loop devices.
CmdlineBuilder args = OR_RETURN(GetArtExecCmdlineBuilder());
args.Add("--")
.Add("/system/bin/apexd")
.Add("--unmount-all")
.Add("--also-include-staged-apexes");
- if (Result<void> result = Run("apexd", args.Get()); !result.ok()) {
- // Maybe apexd is not executable because a previous setup/teardown failed halfway (e.g.,
- // /system is currently mounted but /dev is not). We do a check below to see if there is any
- // unmounted APEXes.
- LOG(WARNING) << "Failed to run apexd: " << result.error().message();
- }
+ OR_RETURN(Run("apexd", args.Get()));
}
- std::vector<FstabEntry> apex_entries =
- OR_RETURN(GetProcMountsDescendantsOfPath(PathInChroot("/apex")));
+ // Double check to make sure all APEXes are unmounted, just in case apexd incorrectly reported
+ // success.
+ apex_entries = OR_RETURN(GetProcMountsDescendantsOfPath(PathInChroot("/apex")));
for (const FstabEntry& entry : apex_entries) {
if (entry.mount_point != PathInChroot("/apex")) {
return Errorf("apexd didn't unmount '{}'. See logs for details", entry.mount_point);