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
// mount point mounting our desired partition, and then bind mount the target folder.
dev_t preinit_dev = st.st_rdev;
bool mounted = false;
for (const auto &info: self_mount_info) {
if (info.root == "/" && info.device == preinit_dev) {
auto flags = split_ro(info.fs_option, ",");
@ -78,12 +79,17 @@ static void mount_mirrors() {
string preinit_dir = resolve_preinit_dir(info.target.data());
xmkdir(preinit_dir.data(), 0700);
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);
break;
}
}
}
if (!mounted) {
LOGW("preinit mirror not mounted %u:%u\n", major(preinit_dev), minor(preinit_dev));
unlink((MAGISKTMP + "/" PREINITDEV).data());
}
}
// Prepare worker
auto worker_dir = MAGISKTMP + "/" WORKERDIR;