Maintain a list of pre-init mounts

Keep track of everything to unmount
This commit is contained in:
topjohnwu 2019-07-16 23:54:52 -07:00
parent aa47966347
commit 736729f5ef
3 changed files with 15 additions and 5 deletions

View File

@ -109,10 +109,12 @@ static void main_daemon() {
restore_rootcon();
// Unmount pre-init patches
umount2("/init", MNT_DETACH);
umount2("/init.rc", MNT_DETACH);
umount2("/system/lib/libselinux.so", MNT_DETACH);
umount2("/system/lib64/libselinux.so", MNT_DETACH);
if (access(ROOTMNT, F_OK) == 0) {
file_readline(ROOTMNT, [](auto line) -> bool {
umount2(line.data(), MNT_DETACH);
return true;
}, true);
}
int fd = xopen("/dev/null", O_RDWR | O_CLOEXEC);
xdup2(fd, STDOUT_FILENO);

View File

@ -12,6 +12,8 @@
#define BLOCKDIR MAGISKTMP "/block"
#define BBPATH MAGISKTMP "/busybox"
#define MODULEMNT MAGISKTMP "/modules"
#define ROOTOVL MAGISKTMP "/rootdir"
#define ROOTMNT ROOTOVL "/.mount_list"
#define SECURE_DIR "/data/adb"
#define MODULEROOT SECURE_DIR "/modules"
#define MODULEUPGRADE SECURE_DIR "/modules_update"

View File

@ -225,13 +225,14 @@ static void sbin_overlay(const raw_data &self, const raw_data &config) {
xsymlink("./magiskinit", "/sbin/supolicy");
}
#define ROOTOVL MAGISKTMP "/rootdir"
#define ROOTMIR MIRRDIR "/system_root"
#define ROOTBLK BLOCKDIR "/system_root"
#define MONOPOLICY "/sepolicy"
#define PATCHPOLICY "/sbin/.se"
#define LIBSELINUX "/system/" LIBNAME "/libselinux.so"
static string mount_list;
static void magic_mount(int dirfd, const string &path) {
DIR *dir = xfdopendir(dirfd);
for (dirent *entry; (entry = readdir(dir));) {
@ -248,6 +249,8 @@ static void magic_mount(int dirfd, const string &path) {
string src = ROOTOVL + dest;
LOGD("Mount [%s] -> [%s]\n", src.data(), dest.data());
xmount(src.data(), dest.data(), nullptr, MS_BIND, nullptr);
mount_list += dest;
mount_list += '\n';
}
}
}
@ -376,6 +379,9 @@ void SARCommon::patch_rootdir() {
src = xopen(ROOTOVL, O_RDONLY | O_CLOEXEC);
magic_mount(src, "");
close(src);
dest = xopen(ROOTMNT, O_WRONLY | O_CREAT | O_CLOEXEC);
write(dest, mount_list.data(), mount_list.length());
close(dest);
}
#define FSR "/first_stage_ramdisk"