mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 13:35:27 +00:00
Add MS_SILENT to xmount and cleanup function wraps
This commit is contained in:
parent
bcae9dec41
commit
1c743839ea
@ -186,7 +186,7 @@ void daemon_init() {
|
|||||||
// Check whether skip_initramfs device
|
// Check whether skip_initramfs device
|
||||||
vec_for_each(&mounts, line) {
|
vec_for_each(&mounts, line) {
|
||||||
if (strstr(line, " /system_root ")) {
|
if (strstr(line, " /system_root ")) {
|
||||||
xmkdir_p(MIRRDIR "/system", 0755);
|
xmkdirs(MIRRDIR "/system", 0755);
|
||||||
bind_mount("/system_root/system", MIRRDIR "/system");
|
bind_mount("/system_root/system", MIRRDIR "/system");
|
||||||
skip_initramfs = 1;
|
skip_initramfs = 1;
|
||||||
break;
|
break;
|
||||||
@ -195,7 +195,7 @@ void daemon_init() {
|
|||||||
vec_for_each(&mounts, line) {
|
vec_for_each(&mounts, line) {
|
||||||
if (!skip_initramfs && strstr(line, " /system ")) {
|
if (!skip_initramfs && strstr(line, " /system ")) {
|
||||||
sscanf(line, "%s", buf);
|
sscanf(line, "%s", buf);
|
||||||
xmkdir_p(MIRRDIR "/system", 0755);
|
xmkdirs(MIRRDIR "/system", 0755);
|
||||||
xmount(buf, MIRRDIR "/system", "ext4", MS_RDONLY, NULL);
|
xmount(buf, MIRRDIR "/system", "ext4", MS_RDONLY, NULL);
|
||||||
#ifdef MAGISK_DEBUG
|
#ifdef MAGISK_DEBUG
|
||||||
LOGI("mount: %s -> %s\n", buf, MIRRDIR "/system");
|
LOGI("mount: %s -> %s\n", buf, MIRRDIR "/system");
|
||||||
@ -205,7 +205,7 @@ void daemon_init() {
|
|||||||
} else if (strstr(line, " /vendor ")) {
|
} else if (strstr(line, " /vendor ")) {
|
||||||
seperate_vendor = 1;
|
seperate_vendor = 1;
|
||||||
sscanf(line, "%s", buf);
|
sscanf(line, "%s", buf);
|
||||||
xmkdir_p(MIRRDIR "/vendor", 0755);
|
xmkdirs(MIRRDIR "/vendor", 0755);
|
||||||
xmount(buf, MIRRDIR "/vendor", "ext4", MS_RDONLY, NULL);
|
xmount(buf, MIRRDIR "/vendor", "ext4", MS_RDONLY, NULL);
|
||||||
#ifdef MAGISK_DEBUG
|
#ifdef MAGISK_DEBUG
|
||||||
LOGI("mount: %s -> %s\n", buf, MIRRDIR "/vendor");
|
LOGI("mount: %s -> %s\n", buf, MIRRDIR "/vendor");
|
||||||
@ -224,11 +224,11 @@ void daemon_init() {
|
|||||||
LOGI("link: %s\n", MIRRDIR "/vendor");
|
LOGI("link: %s\n", MIRRDIR "/vendor");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
xmkdir_p(MIRRDIR "/bin", 0755);
|
xmkdirs(MIRRDIR "/bin", 0755);
|
||||||
bind_mount(DATABIN, MIRRDIR "/bin");
|
bind_mount(DATABIN, MIRRDIR "/bin");
|
||||||
|
|
||||||
LOGI("* Setting up internal busybox");
|
LOGI("* Setting up internal busybox");
|
||||||
xmkdir_p(BBPATH, 0755);
|
xmkdirs(BBPATH, 0755);
|
||||||
exec_command_sync(MIRRDIR "/bin/busybox", "--install", "-s", BBPATH, NULL);
|
exec_command_sync(MIRRDIR "/bin/busybox", "--install", "-s", BBPATH, NULL);
|
||||||
xsymlink(MIRRDIR "/bin/busybox", BBPATH "/busybox");
|
xsymlink(MIRRDIR "/bin/busybox", BBPATH "/busybox");
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ static void parse_cmdline(struct cmdline *cmd) {
|
|||||||
|
|
||||||
char cmdline[4096];
|
char cmdline[4096];
|
||||||
mkdir("/proc", 0555);
|
mkdir("/proc", 0555);
|
||||||
mount("proc", "/proc", "proc", 0, NULL);
|
xmount("proc", "/proc", "proc", 0, NULL);
|
||||||
int fd = open("/proc/cmdline", O_RDONLY | O_CLOEXEC);
|
int fd = open("/proc/cmdline", O_RDONLY | O_CLOEXEC);
|
||||||
cmdline[read(fd, cmdline, sizeof(cmdline))] = '\0';
|
cmdline[read(fd, cmdline, sizeof(cmdline))] = '\0';
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -455,7 +455,7 @@ int main(int argc, char *argv[]) {
|
|||||||
frm_rf(root);
|
frm_rf(root);
|
||||||
|
|
||||||
mkdir("/sys", 0755);
|
mkdir("/sys", 0755);
|
||||||
mount("sysfs", "/sys", "sysfs", 0, NULL);
|
xmount("sysfs", "/sys", "sysfs", 0, NULL);
|
||||||
|
|
||||||
char partname[32];
|
char partname[32];
|
||||||
snprintf(partname, sizeof(partname), "system%s", cmd.slot);
|
snprintf(partname, sizeof(partname), "system%s", cmd.slot);
|
||||||
@ -464,20 +464,20 @@ int main(int argc, char *argv[]) {
|
|||||||
setup_block(&dev, partname);
|
setup_block(&dev, partname);
|
||||||
|
|
||||||
mkdir("/system_root", 0755);
|
mkdir("/system_root", 0755);
|
||||||
mount(dev.path, "/system_root", "ext4", MS_RDONLY, NULL);
|
xmount(dev.path, "/system_root", "ext4", MS_RDONLY, NULL);
|
||||||
int system_root = open("/system_root", O_RDONLY | O_CLOEXEC);
|
int system_root = open("/system_root", O_RDONLY | O_CLOEXEC);
|
||||||
|
|
||||||
// Exclude system folder
|
// Exclude system folder
|
||||||
excl_list = (char *[]) { "system", NULL };
|
excl_list = (char *[]) { "system", NULL };
|
||||||
clone_dir(system_root, root);
|
clone_dir(system_root, root);
|
||||||
mkdir("/system", 0755);
|
mkdir("/system", 0755);
|
||||||
mount("/system_root/system", "/system", NULL, MS_BIND, NULL);
|
xmount("/system_root/system", "/system", NULL, MS_BIND, NULL);
|
||||||
|
|
||||||
snprintf(partname, sizeof(partname), "vendor%s", cmd.slot);
|
snprintf(partname, sizeof(partname), "vendor%s", cmd.slot);
|
||||||
|
|
||||||
// We need to mount independent vendor partition
|
// We need to mount independent vendor partition
|
||||||
if (setup_block(&dev, partname) == 0)
|
if (setup_block(&dev, partname) == 0)
|
||||||
mount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
|
xmount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
|
||||||
|
|
||||||
close(system_root);
|
close(system_root);
|
||||||
} else {
|
} else {
|
||||||
@ -515,13 +515,13 @@ int main(int argc, char *argv[]) {
|
|||||||
if (patch_sepolicy()) {
|
if (patch_sepolicy()) {
|
||||||
/* Non skip_initramfs devices using separate sepolicy
|
/* Non skip_initramfs devices using separate sepolicy
|
||||||
* Mount /system and try to load again */
|
* Mount /system and try to load again */
|
||||||
mount("sysfs", "/sys", "sysfs", 0, NULL);
|
xmount("sysfs", "/sys", "sysfs", 0, NULL);
|
||||||
struct device dev;
|
struct device dev;
|
||||||
setup_block(&dev, "system");
|
setup_block(&dev, "system");
|
||||||
mount(dev.path, "/system", "ext4", MS_RDONLY, NULL);
|
xmount(dev.path, "/system", "ext4", MS_RDONLY, NULL);
|
||||||
// We need to mount independent vendor partition
|
// We need to mount independent vendor partition
|
||||||
if (setup_block(&dev, "vendor") == 0)
|
if (setup_block(&dev, "vendor") == 0)
|
||||||
mount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
|
xmount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
|
||||||
|
|
||||||
patch_sepolicy();
|
patch_sepolicy();
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ int xumount(const char *target);
|
|||||||
int xumount2(const char *target, int flags);
|
int xumount2(const char *target, int flags);
|
||||||
int xrename(const char *oldpath, const char *newpath);
|
int xrename(const char *oldpath, const char *newpath);
|
||||||
int xmkdir(const char *pathname, mode_t mode);
|
int xmkdir(const char *pathname, mode_t mode);
|
||||||
int xmkdir_p(const char *pathname, mode_t mode);
|
int xmkdirs(const char *pathname, mode_t mode);
|
||||||
int xmkdirat(int dirfd, const char *pathname, mode_t mode);
|
int xmkdirat(int dirfd, const char *pathname, mode_t mode);
|
||||||
void *xmmap(void *addr, size_t length, int prot, int flags,
|
void *xmmap(void *addr, size_t length, int prot, int flags,
|
||||||
int fd, off_t offset);
|
int fd, off_t offset);
|
||||||
@ -101,7 +101,7 @@ struct file_attr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int fd_getpath(int fd, char *path, size_t size);
|
int fd_getpath(int fd, char *path, size_t size);
|
||||||
int mkdir_p(const char *pathname, mode_t mode);
|
int mkdirs(const char *pathname, mode_t mode);
|
||||||
void in_order_walk(int dirfd, void (*callback)(int, struct dirent*));
|
void in_order_walk(int dirfd, void (*callback)(int, struct dirent*));
|
||||||
void rm_rf(const char *path);
|
void rm_rf(const char *path);
|
||||||
void frm_rf(int dirfd);
|
void frm_rf(int dirfd);
|
||||||
|
@ -68,10 +68,8 @@ static void store_zygote_ns(int pid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void lazy_unmount(const char* mountpoint) {
|
static void lazy_unmount(const char* mountpoint) {
|
||||||
if (umount2(mountpoint, MNT_DETACH) != -1)
|
if (xumount2(mountpoint, MNT_DETACH) != -1)
|
||||||
LOGD("hide_daemon: Unmounted (%s)\n", mountpoint);
|
LOGD("hide_daemon: Unmounted (%s)\n", mountpoint);
|
||||||
else
|
|
||||||
LOGD("hide_daemon: Unmount Failed (%s)\n", mountpoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hide_daemon(int pid, int ppid) {
|
static void hide_daemon(int pid, int ppid) {
|
||||||
|
@ -34,7 +34,7 @@ int fd_getpath(int fd, char *path, size_t size) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mkdir_p(const char *pathname, mode_t mode) {
|
int mkdirs(const char *pathname, mode_t mode) {
|
||||||
char *path = strdup(pathname), *p;
|
char *path = strdup(pathname), *p;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
for (p = path + 1; *p; ++p) {
|
for (p = path + 1; *p; ++p) {
|
||||||
@ -107,7 +107,7 @@ void mv_f(const char *source, const char *destination) {
|
|||||||
struct file_attr a;
|
struct file_attr a;
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
xmkdir_p(destination, st.st_mode & 0777);
|
xmkdirs(destination, st.st_mode & 0777);
|
||||||
src = xopen(source, O_RDONLY | O_CLOEXEC);
|
src = xopen(source, O_RDONLY | O_CLOEXEC);
|
||||||
dest = xopen(destination, O_RDONLY | O_CLOEXEC);
|
dest = xopen(destination, O_RDONLY | O_CLOEXEC);
|
||||||
fclone_attr(src, dest);
|
fclone_attr(src, dest);
|
||||||
@ -162,7 +162,7 @@ void cp_afc(const char *source, const char *destination) {
|
|||||||
getattr(source, &a);
|
getattr(source, &a);
|
||||||
|
|
||||||
if (S_ISDIR(a.st.st_mode)) {
|
if (S_ISDIR(a.st.st_mode)) {
|
||||||
xmkdir_p(destination, a.st.st_mode & 0777);
|
xmkdirs(destination, a.st.st_mode & 0777);
|
||||||
src = xopen(source, O_RDONLY | O_CLOEXEC);
|
src = xopen(source, O_RDONLY | O_CLOEXEC);
|
||||||
dest = xopen(destination, O_RDONLY | O_CLOEXEC);
|
dest = xopen(destination, O_RDONLY | O_CLOEXEC);
|
||||||
fsetattr(dest, &a);
|
fsetattr(dest, &a);
|
||||||
|
@ -139,9 +139,9 @@ char *mount_image(const char *img, const char *target) {
|
|||||||
if (access(img, F_OK) == -1)
|
if (access(img, F_OK) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (access(target, F_OK) == -1) {
|
if (access(target, F_OK) == -1) {
|
||||||
if (xmkdir_p(target, 0755) == -1) {
|
if (xmkdirs(target, 0755) == -1) {
|
||||||
xmount(NULL, "/", NULL, MS_REMOUNT, NULL);
|
xmount(NULL, "/", NULL, MS_REMOUNT, NULL);
|
||||||
xmkdir_p(target, 0755);
|
xmkdirs(target, 0755);
|
||||||
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
|
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,7 +304,7 @@ int switch_mnt_ns(int pid) {
|
|||||||
fd = xopen(mnt, O_RDONLY);
|
fd = xopen(mnt, O_RDONLY);
|
||||||
if (fd < 0) return 1;
|
if (fd < 0) return 1;
|
||||||
// Switch to its namespace
|
// Switch to its namespace
|
||||||
ret = setns(fd, 0);
|
ret = xsetns(fd, 0);
|
||||||
close(fd);
|
close(fd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -156,14 +156,6 @@ int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
|
||||||
int ret = connect(sockfd, addr, addrlen);
|
|
||||||
if (ret == -1) {
|
|
||||||
PLOGE("connect");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int xlisten(int sockfd, int backlog) {
|
int xlisten(int sockfd, int backlog) {
|
||||||
int ret = listen(sockfd, backlog);
|
int ret = listen(sockfd, backlog);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
@ -229,14 +221,6 @@ int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xsocketpair(int domain, int type, int protocol, int sv[2]) {
|
|
||||||
int ret = socketpair(domain, type, protocol, sv);
|
|
||||||
if (ret == -1) {
|
|
||||||
PLOGE("socketpair");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int xstat(const char *pathname, struct stat *buf) {
|
int xstat(const char *pathname, struct stat *buf) {
|
||||||
int ret = stat(pathname, buf);
|
int ret = stat(pathname, buf);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
@ -292,7 +276,7 @@ int xsymlink(const char *target, const char *linkpath) {
|
|||||||
int xmount(const char *source, const char *target,
|
int xmount(const char *source, const char *target,
|
||||||
const char *filesystemtype, unsigned long mountflags,
|
const char *filesystemtype, unsigned long mountflags,
|
||||||
const void *data) {
|
const void *data) {
|
||||||
int ret = mount(source, target, filesystemtype, mountflags, data);
|
int ret = mount(source, target, filesystemtype, MS_SILENT | mountflags, data);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
PLOGE("mount %s->%s", source, target);
|
PLOGE("mount %s->%s", source, target);
|
||||||
}
|
}
|
||||||
@ -331,10 +315,10 @@ int xmkdir(const char *pathname, mode_t mode) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xmkdir_p(const char *pathname, mode_t mode) {
|
int xmkdirs(const char *pathname, mode_t mode) {
|
||||||
int ret = mkdir_p(pathname, mode);
|
int ret = mkdirs(pathname, mode);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
PLOGE("mkdir_p %s", pathname);
|
PLOGE("mkdirs %s", pathname);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user