From 9449583bc36c9148fde4f7249bdb74a8e6d4d637 Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Wed, 30 Dec 2020 20:11:24 +0100 Subject: [PATCH] init: Sort the list of flattened APEX folders to avoid variations * In 'ActivateFlattenedApexesFrom', the 'readdir' detects the APEX folders in a random way that depends on filesystems, built packages and order of the build chain * In normal cases, this is not an issue, however when building with Go configurations, we have a case where the package 'com.android.tethering.inprocess' is built along the 'com.android.tethering' overriden binary, and depending on the 'readdir' output, the mounts break the Tethering service Change-Id: I8ac4a0284d8d885f732c71e846933869cf16a0bd Signed-off-by: Adrian DC --- init/mount_namespace.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/init/mount_namespace.cpp b/init/mount_namespace.cpp index 59cc140e4..ec48cde02 100644 --- a/init/mount_namespace.cpp +++ b/init/mount_namespace.cpp @@ -115,22 +115,29 @@ static Result ActivateFlattenedApexesFrom(const std::string& from_dir, return {}; } dirent* entry; + std::vector entries; + while ((entry = readdir(dir.get())) != nullptr) { if (entry->d_name[0] == '.') continue; if (entry->d_type == DT_DIR) { - const std::string apex_path = from_dir + "/" + entry->d_name; - const auto apex_manifest = GetApexManifest(apex_path); - if (!apex_manifest.ok()) { - LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_manifest.error(); - continue; - } - const std::string mount_path = to_dir + "/" + apex_manifest->name(); - if (auto result = MountDir(apex_path, mount_path); !result.ok()) { - return result; - } - on_activate(apex_path, *apex_manifest); + entries.push_back(entry->d_name); } } + + std::sort(entries.begin(), entries.end()); + for (const auto& name : entries) { + const std::string apex_path = from_dir + "/" + name; + const auto apex_manifest = GetApexManifest(apex_path); + if (!apex_manifest.ok()) { + LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_manifest.error(); + continue; + } + const std::string mount_path = to_dir + "/" + apex_manifest->name(); + if (auto result = MountDir(apex_path, mount_path); !result.ok()) { + return result; + } + on_activate(apex_path, *apex_manifest); + } return {}; }