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
This commit is contained in:
Jiyong Park 2019-12-08 00:25:15 +09:00
parent 8afa4a0637
commit 648ae3a9d3
3 changed files with 22 additions and 22 deletions

View file

@ -71,6 +71,7 @@ cc_defaults {
"libpropertyinfoserializer",
"libpropertyinfoparser",
"libsnapshot_init",
"lib_apex_manifest_proto_lite",
],
shared_libs: [
"libbacktrace",

View file

@ -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 \

View file

@ -27,6 +27,7 @@
#include <android-base/properties.h>
#include <android-base/result.h>
#include <android-base/unique_fd.h>
#include <apex_manifest.pb.h>
#include "util.h"
@ -90,6 +91,19 @@ static Result<void> MountDir(const std::string& path, const std::string& mount_p
return {};
}
static Result<std::string> 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<void> ActivateFlattenedApexesFrom(const std::string& from_dir,
const std::string& to_dir) {
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(from_dir.c_str()), closedir);
@ -101,7 +115,12 @@ static Result<void> 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<std::string> 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;