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;