mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Use pidfd_open for setns
which is more efficient on newer kernel
This commit is contained in:
parent
941a363c5a
commit
c6f0762510
@ -208,16 +208,22 @@ uint32_t binary_gcd(uint32_t u, uint32_t v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int switch_mnt_ns(int pid) {
|
int switch_mnt_ns(int pid) {
|
||||||
char mnt[32];
|
int ret = -1;
|
||||||
ssprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
|
int fd = syscall(__NR_pidfd_open, pid, 0);
|
||||||
if (access(mnt, R_OK) == -1) return 1; // Maybe process died..
|
if (fd > 0) {
|
||||||
|
ret = setns(fd, CLONE_NEWNS);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
if (ret < 0) {
|
||||||
|
char mnt[32];
|
||||||
|
ssprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
|
||||||
|
fd = open(mnt, O_RDONLY);
|
||||||
|
if (fd < 0) return 1; // Maybe process died..
|
||||||
|
|
||||||
int fd, ret;
|
// Switch to its namespace
|
||||||
fd = xopen(mnt, O_RDONLY);
|
ret = xsetns(fd, 0);
|
||||||
if (fd < 0) return 1;
|
close(fd);
|
||||||
// Switch to its namespace
|
}
|
||||||
ret = xsetns(fd, 0);
|
|
||||||
close(fd);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user