From 648ae3a9d321bbca74f6aa9d5167d4f9a8401ded Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Sun, 8 Dec 2019 00:25:15 +0900 Subject: [PATCH] Use apex name in apex_manifest.pb as the mount point When bind-mounting flattened APEX, use the apex name found in apex_manifest.pb as the mount point, instead of the directory name which might be different from apex name in case when the apex is overridden. This allowed us to remove the special casing for the ART apex since we /system/apex/com.android.art.release will be mounted to /apex/com.android.art instead of /apex/com.android.art.release. Bug: N/A Test: m Test: OVERRIDE_TARGET_FLATTEN_APEX=true m, device is bootable Change-Id: Ibdde7002b9078db390e6672b0eb82c474925451d --- init/Android.bp | 1 + init/Android.mk | 1 - init/mount_namespace.cpp | 42 ++++++++++++++++++++-------------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/init/Android.bp b/init/Android.bp index 9529617c6..42d0b33da 100644 --- a/init/Android.bp +++ b/init/Android.bp @@ -71,6 +71,7 @@ cc_defaults { "libpropertyinfoserializer", "libpropertyinfoparser", "libsnapshot_init", + "lib_apex_manifest_proto_lite", ], shared_libs: [ "libbacktrace", diff --git a/init/Android.mk b/init/Android.mk index ee2d89ac9..07b0f950f 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -52,7 +52,6 @@ LOCAL_SRC_FILES := \ first_stage_init.cpp \ first_stage_main.cpp \ first_stage_mount.cpp \ - mount_namespace.cpp \ reboot_utils.cpp \ selabel.cpp \ selinux.cpp \ diff --git a/init/mount_namespace.cpp b/init/mount_namespace.cpp index c33e0de7a..648b3bb0e 100644 --- a/init/mount_namespace.cpp +++ b/init/mount_namespace.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "util.h" @@ -90,6 +91,19 @@ static Result MountDir(const std::string& path, const std::string& mount_p return {}; } +static Result GetApexName(const std::string& apex_dir) { + const std::string manifest_path = apex_dir + "/apex_manifest.pb"; + std::string content; + if (!android::base::ReadFileToString(manifest_path, &content)) { + return Error() << "Failed to read manifest file: " << manifest_path; + } + apex::proto::ApexManifest manifest; + if (!manifest.ParseFromString(content)) { + return Error() << "Can't parse manifest file: " << manifest_path; + } + return manifest.name(); +} + static Result ActivateFlattenedApexesFrom(const std::string& from_dir, const std::string& to_dir) { std::unique_ptr dir(opendir(from_dir.c_str()), closedir); @@ -101,7 +115,12 @@ static Result ActivateFlattenedApexesFrom(const std::string& from_dir, if (entry->d_name[0] == '.') continue; if (entry->d_type == DT_DIR) { const std::string apex_path = from_dir + "/" + entry->d_name; - const std::string mount_path = to_dir + "/" + entry->d_name; + const auto apex_name = GetApexName(apex_path); + if (!apex_name) { + LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_name.error(); + continue; + } + const std::string mount_path = to_dir + "/" + (*apex_name); if (auto result = MountDir(apex_path, mount_path); !result) { return result; } @@ -129,26 +148,7 @@ static bool ActivateFlattenedApexesIfPossible() { return false; } } - // Special casing for the ART APEX - constexpr const char kArtApexMountPath[] = "/apex/com.android.art"; - static const std::vector kArtApexDirNames = {"com.android.art.release", - "com.android.art.debug"}; - bool success = false; - for (const auto& name : kArtApexDirNames) { - std::string path = kApexTop + "/" + name; - if (access(path.c_str(), F_OK) == 0) { - if (auto result = MountDir(path, kArtApexMountPath); !result) { - LOG(ERROR) << result.error(); - return false; - } - success = true; - break; - } - } - if (!success) { - PLOG(ERROR) << "Failed to bind mount the ART APEX to " << kArtApexMountPath; - } - return success; + return true; } static android::base::unique_fd bootstrap_ns_fd;