Unlink preinit device if bind mount fails

This commit is contained in:
LoveSy 2023-03-22 10:48:02 +08:00 committed by John Wu
parent dba5020e4f
commit e893c13cf1

View File

@ -68,6 +68,7 @@ static void mount_mirrors() {
// What we do instead is to scan through the current mountinfo and find a pre-existing // What we do instead is to scan through the current mountinfo and find a pre-existing
// mount point mounting our desired partition, and then bind mount the target folder. // mount point mounting our desired partition, and then bind mount the target folder.
dev_t preinit_dev = st.st_rdev; dev_t preinit_dev = st.st_rdev;
bool mounted = false;
for (const auto &info: self_mount_info) { for (const auto &info: self_mount_info) {
if (info.root == "/" && info.device == preinit_dev) { if (info.root == "/" && info.device == preinit_dev) {
auto flags = split_ro(info.fs_option, ","); auto flags = split_ro(info.fs_option, ",");
@ -78,11 +79,16 @@ static void mount_mirrors() {
string preinit_dir = resolve_preinit_dir(info.target.data()); string preinit_dir = resolve_preinit_dir(info.target.data());
xmkdir(preinit_dir.data(), 0700); xmkdir(preinit_dir.data(), 0700);
auto mirror_dir = MAGISKTMP + "/" PREINITMIRR; auto mirror_dir = MAGISKTMP + "/" PREINITMIRR;
mount_mirror(preinit_dir, mirror_dir); if ((mounted = mount_mirror(preinit_dir, mirror_dir))) {
xmount(nullptr, mirror_dir.data(), nullptr, MS_UNBINDABLE, nullptr); xmount(nullptr, mirror_dir.data(), nullptr, MS_UNBINDABLE, nullptr);
break; break;
}
} }
} }
if (!mounted) {
LOGW("preinit mirror not mounted %u:%u\n", major(preinit_dev), minor(preinit_dev));
unlink((MAGISKTMP + "/" PREINITDEV).data());
}
} }
// Prepare worker // Prepare worker