magiskinit: Only unmount /system and /vendor if it was mounted by magisk

This fixes an issue where if /system or /vendor was already mounted
prior to magiskinit running, then they would get unmounted.

Signed-off-by: Andrew Gunnerson <andrewgunnerson@gmail.com>
This commit is contained in:
Andrew Gunnerson 2018-05-19 19:57:50 -04:00 committed by John Wu
parent b8bd83ba05
commit b3cd83bbca

View File

@ -418,6 +418,9 @@ int main(int argc, char *argv[]) {
* Early Mount
* ************/
int mounted_system = 0;
int mounted_vendor = 0;
// If skip_initramfs or using split policies, we need early mount
if (cmd.skip_initramfs || access("/sepolicy", R_OK) != 0) {
char partname[32];
@ -444,12 +447,15 @@ int main(int argc, char *argv[]) {
xmount("/system_root/system", "/system", NULL, MS_BIND, NULL);
} else {
xmount(dev.path, "/system", "ext4", MS_RDONLY, NULL);
mounted_system = 1;
}
// Mount vendor
snprintf(partname, sizeof(partname), "vendor%s", cmd.slot);
if (setup_block(&dev, partname) == 0)
if (setup_block(&dev, partname) == 0) {
xmount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
mounted_vendor = 1;
}
}
/* *************
@ -480,8 +486,9 @@ int main(int argc, char *argv[]) {
// Clean up
close(root);
if (!cmd.skip_initramfs)
if (mounted_system)
umount("/system");
if (mounted_vendor)
umount("/vendor");
// Finally, give control back!