Returned fds[0] in socketpair() might be STDOUT

* There will be garbage output when executing `su` (#4016)
* Failed to check root status and showing N/A in status (#4005)

Signed-off-by: Shaka Huang <shakalaca@gmail.com>
This commit is contained in:
Shaka Huang 2021-03-13 01:47:13 +08:00 committed by John Wu
parent a6f81c66e5
commit b9cdc755d1

View File

@ -172,8 +172,6 @@ static int switch_cgroup(const char *cgroup, int pid) {
// Change process name
set_nice_name("magiskd");
magisk_logging();
int fd = xopen("/dev/null", O_WRONLY);
xdup2(fd, STDOUT_FILENO);
xdup2(fd, STDERR_FILENO);
@ -184,6 +182,8 @@ static int switch_cgroup(const char *cgroup, int pid) {
if (fd > STDERR_FILENO)
close(fd);
magisk_logging();
setsid();
setcon("u:r:" SEPOL_PROC_DOMAIN ":s0");