diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index f232dbe68..78a63bda0 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -62,6 +62,8 @@ static char *loopsetup(const char *img) { return NULL; strcpy((char *) info.lo_file_name, img); ioctl(lfd, LOOP_SET_STATUS64, &info); + close(lfd); + close(ffd); return strdup(device); } @@ -241,6 +243,7 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) { insert_child(node, dummy); } } + closedir(dir); snprintf(buf, PATH_MAX, "/dev/magisk/dummy%s", real_path); xmkdir_p(buf, 0755); diff --git a/jni/daemon/daemon.c b/jni/daemon/daemon.c index 070bfcef3..e07da923c 100644 --- a/jni/daemon/daemon.c +++ b/jni/daemon/daemon.c @@ -23,6 +23,7 @@ #include "magiskpolicy.h" pthread_t sepol_patch; +int null_fd; static void *request_handler(void *args) { // Setup the default error handler for threads @@ -111,9 +112,10 @@ void start_daemon() { xsetsid(); setcon("u:r:su:s0"); umask(022); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); + null_fd = xopen("/dev/null", O_RDWR); + xdup2(null_fd, STDIN_FILENO); + xdup2(null_fd, STDOUT_FILENO); + xdup2(null_fd, STDERR_FILENO); // Patch selinux with medium patch before we do anything load_policydb(SELINUX_POLICY); diff --git a/jni/daemon/log_monitor.c b/jni/daemon/log_monitor.c index e6e4b0aa6..8f7486733 100644 --- a/jni/daemon/log_monitor.c +++ b/jni/daemon/log_monitor.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "magisk.h" #include "utils.h" @@ -29,6 +30,7 @@ static void *logger_thread(void *args) { while (fdgets(buffer, sizeof(buffer), fd)) { fprintf(logfile, "%s", buffer); } + close(fd); return NULL; } diff --git a/jni/magisk.h b/jni/magisk.h index 60f77eee9..d3ca765da 100644 --- a/jni/magisk.h +++ b/jni/magisk.h @@ -55,6 +55,7 @@ extern char *argv0; /* For changing process name */ extern char *applet[]; extern int (*applet_main[]) (int, char *[]); +extern int null_fd; // Multi-call entrypoints int magiskhide_main(int argc, char *argv[]); diff --git a/jni/utils/misc.c b/jni/utils/misc.c index db4537821..865cbeab1 100644 --- a/jni/utils/misc.c +++ b/jni/utils/misc.c @@ -45,17 +45,18 @@ unsigned get_radio_uid() { } int check_data() { + int ret = 0; char buffer[4096]; FILE *fp = xfopen("/proc/mounts", "r"); while (fgets(buffer, sizeof(buffer), fp)) { if (strstr(buffer, " /data ")) { - if (strstr(buffer, "tmpfs")) - return 0; - else - return 1; + if (strstr(buffer, "tmpfs") == NULL) + ret = 1; + break; } } - return 0; + fclose(fp); + return ret; } /* All the string should be freed manually!! */ @@ -238,10 +239,6 @@ int run_command(int *fd, const char *path, char *const argv[]) { xdup2(sv[0], STDIN_FILENO); xdup2(sv[0], STDOUT_FILENO); xdup2(sv[0], STDERR_FILENO); - } else { - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); } execv(path, argv);