Micro optimizations

This commit is contained in:
topjohnwu
2018-11-13 02:07:02 -05:00
parent 9592a69986
commit 3a2a2a4ffa
6 changed files with 26 additions and 26 deletions

View File

@@ -506,21 +506,21 @@ static bool magisk_env() {
strcmp(entry->d_name, ".core") == 0 ||
strcmp(entry->d_name, "lost+found") == 0)
continue;
snprintf(buf, PATH_MAX, "%s/%s/remove", MOUNTPOINT, entry->d_name);
if (access(buf, F_OK) == 0) {
snprintf(buf, PATH_MAX, "%s/%s", MOUNTPOINT, entry->d_name);
snprintf(buf, PATH_MAX, "%s/%s", MOUNTPOINT, entry->d_name);
chdir(buf);
if (access("remove", F_OK) == 0) {
chdir("..");
rm_rf(buf);
continue;
}
snprintf(buf, PATH_MAX, "%s/%s/update", MOUNTPOINT, entry->d_name);
unlink(buf);
snprintf(buf, PATH_MAX, "%s/%s/disable", MOUNTPOINT, entry->d_name);
if (access(buf, F_OK) == 0)
unlink("update");
if (access("disable", F_OK) == 0)
continue;
module_list.push_back(entry->d_name);
}
}
closedir(dir);
chdir("/");
return trim_img(MAINIMG, MOUNTPOINT, magiskloop) == 0;
}

View File

@@ -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() {
struct sockaddr_un sun;
socklen_t len = setup_sockaddr(&sun, MAIN_SOCKET);