mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 11:07:38 +00:00
Micro optimizations
This commit is contained in:
parent
9592a69986
commit
3a2a2a4ffa
@ -506,21 +506,21 @@ static bool magisk_env() {
|
|||||||
strcmp(entry->d_name, ".core") == 0 ||
|
strcmp(entry->d_name, ".core") == 0 ||
|
||||||
strcmp(entry->d_name, "lost+found") == 0)
|
strcmp(entry->d_name, "lost+found") == 0)
|
||||||
continue;
|
continue;
|
||||||
snprintf(buf, PATH_MAX, "%s/%s/remove", MOUNTPOINT, entry->d_name);
|
snprintf(buf, PATH_MAX, "%s/%s", MOUNTPOINT, entry->d_name);
|
||||||
if (access(buf, F_OK) == 0) {
|
chdir(buf);
|
||||||
snprintf(buf, PATH_MAX, "%s/%s", MOUNTPOINT, entry->d_name);
|
if (access("remove", F_OK) == 0) {
|
||||||
|
chdir("..");
|
||||||
rm_rf(buf);
|
rm_rf(buf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
snprintf(buf, PATH_MAX, "%s/%s/update", MOUNTPOINT, entry->d_name);
|
unlink("update");
|
||||||
unlink(buf);
|
if (access("disable", F_OK) == 0)
|
||||||
snprintf(buf, PATH_MAX, "%s/%s/disable", MOUNTPOINT, entry->d_name);
|
|
||||||
if (access(buf, F_OK) == 0)
|
|
||||||
continue;
|
continue;
|
||||||
module_list.push_back(entry->d_name);
|
module_list.push_back(entry->d_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
chdir("/");
|
||||||
|
|
||||||
return trim_img(MAINIMG, MOUNTPOINT, magiskloop) == 0;
|
return trim_img(MAINIMG, MOUNTPOINT, magiskloop) == 0;
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,20 @@ static void main_daemon() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int switch_mnt_ns(int pid) {
|
||||||
|
char mnt[32];
|
||||||
|
snprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
|
||||||
|
if(access(mnt, R_OK) == -1) return 1; // Maybe process died..
|
||||||
|
|
||||||
|
int fd, ret;
|
||||||
|
fd = xopen(mnt, O_RDONLY);
|
||||||
|
if (fd < 0) return 1;
|
||||||
|
// Switch to its namespace
|
||||||
|
ret = xsetns(fd, 0);
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int connect_daemon() {
|
int connect_daemon() {
|
||||||
struct sockaddr_un sun;
|
struct sockaddr_un sun;
|
||||||
socklen_t len = setup_sockaddr(&sun, MAIN_SOCKET);
|
socklen_t len = setup_sockaddr(&sun, MAIN_SOCKET);
|
||||||
|
@ -37,6 +37,7 @@ enum {
|
|||||||
// daemon.c
|
// daemon.c
|
||||||
|
|
||||||
int connect_daemon();
|
int connect_daemon();
|
||||||
|
int switch_mnt_ns(int pid);
|
||||||
|
|
||||||
// log_monitor.c
|
// log_monitor.c
|
||||||
|
|
||||||
|
@ -72,9 +72,10 @@ static void hide_daemon(int pid) {
|
|||||||
if (switch_mnt_ns(pid))
|
if (switch_mnt_ns(pid))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "/proc/%d/mounts", pid);
|
snprintf(buffer, sizeof(buffer), "/proc/%d", pid);
|
||||||
file_to_vector(buffer, mounts);
|
chdir(buffer);
|
||||||
|
|
||||||
|
file_to_vector("mounts", mounts);
|
||||||
// Unmount dummy skeletons and /sbin links
|
// Unmount dummy skeletons and /sbin links
|
||||||
for (auto &s : mounts) {
|
for (auto &s : mounts) {
|
||||||
if (s.contains("tmpfs /system/") || s.contains("tmpfs /vendor/") || s.contains("tmpfs /sbin")) {
|
if (s.contains("tmpfs /system/") || s.contains("tmpfs /vendor/") || s.contains("tmpfs /sbin")) {
|
||||||
@ -85,8 +86,7 @@ static void hide_daemon(int pid) {
|
|||||||
mounts.clear();
|
mounts.clear();
|
||||||
|
|
||||||
// Re-read mount infos
|
// Re-read mount infos
|
||||||
snprintf(buffer, sizeof(buffer), "/proc/%d/mounts", pid);
|
file_to_vector("mounts", mounts);
|
||||||
file_to_vector(buffer, mounts);
|
|
||||||
|
|
||||||
// Unmount everything under /system, /vendor, and loop mounts
|
// Unmount everything under /system, /vendor, and loop mounts
|
||||||
for (auto &s : mounts) {
|
for (auto &s : mounts) {
|
||||||
|
@ -94,7 +94,6 @@ int is_num(const char *s);
|
|||||||
int exec_array(int err, int *fd, void (*cb)(void), const char *argv[]);
|
int exec_array(int err, int *fd, void (*cb)(void), const char *argv[]);
|
||||||
int exec_command(int err, int *fd, void (*cb)(void), const char *argv0, ...);
|
int exec_command(int err, int *fd, void (*cb)(void), const char *argv0, ...);
|
||||||
int exec_command_sync(const char *argv0, ...);
|
int exec_command_sync(const char *argv0, ...);
|
||||||
int switch_mnt_ns(int pid);
|
|
||||||
int fork_dont_care();
|
int fork_dont_care();
|
||||||
void gen_rand_str(char *buf, int len);
|
void gen_rand_str(char *buf, int len);
|
||||||
int strend(const char *s1, const char *s2);
|
int strend(const char *s1, const char *s2);
|
||||||
|
@ -67,20 +67,6 @@ ssize_t fdgets(char *buf, const size_t size, int fd) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int switch_mnt_ns(int pid) {
|
|
||||||
char mnt[32];
|
|
||||||
snprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
|
|
||||||
if(access(mnt, R_OK) == -1) return 1; // Maybe process died..
|
|
||||||
|
|
||||||
int fd, ret;
|
|
||||||
fd = xopen(mnt, O_RDONLY);
|
|
||||||
if (fd < 0) return 1;
|
|
||||||
// Switch to its namespace
|
|
||||||
ret = xsetns(fd, 0);
|
|
||||||
close(fd);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fork_dont_care() {
|
int fork_dont_care() {
|
||||||
int pid = xfork();
|
int pid = xfork();
|
||||||
if (pid) {
|
if (pid) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user