Make sure file descriptors are setup properly

This commit is contained in:
topjohnwu 2019-11-25 19:07:06 -05:00
parent 34bb18448c
commit e373e59661

View File

@ -100,6 +100,18 @@ static void *request_handler(void *args) {
static void main_daemon() { static void main_daemon() {
android_logging(); android_logging();
int fd = xopen("/dev/null", O_WRONLY);
xdup2(fd, STDOUT_FILENO);
xdup2(fd, STDERR_FILENO);
if (fd > STDERR_FILENO)
close(fd);
fd = xopen("/dev/zero", O_RDONLY);
xdup2(fd, STDIN_FILENO);
if (fd > STDERR_FILENO)
close(fd);
close(fd);
setsid(); setsid();
setcon("u:r:" SEPOL_PROC_DOMAIN ":s0"); setcon("u:r:" SEPOL_PROC_DOMAIN ":s0");
restore_rootcon(); restore_rootcon();
@ -112,14 +124,6 @@ static void main_daemon() {
}, true); }, true);
} }
int fd = xopen("/dev/null", O_RDWR | O_CLOEXEC);
xdup2(fd, STDOUT_FILENO);
xdup2(fd, STDERR_FILENO);
close(fd);
fd = xopen("/dev/zero", O_RDWR | O_CLOEXEC);
xdup2(fd, STDIN_FILENO);
close(fd);
LOGI(SHOW_VER(Magisk) " daemon started\n"); LOGI(SHOW_VER(Magisk) " daemon started\n");
// Get server stat // Get server stat