From 022b18c8ced12082e6a56b3cd7072ba83e5dab2f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 23 Dec 2017 04:58:51 +0800 Subject: [PATCH] Properly detect /data status --- core/jni/core/bootstages.c | 2 +- core/jni/core/log_monitor.c | 15 ++++++--------- core/jni/utils/misc.c | 23 ++++++++++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/jni/core/bootstages.c b/core/jni/core/bootstages.c index 711117fdb..fe60182c2 100644 --- a/core/jni/core/bootstages.c +++ b/core/jni/core/bootstages.c @@ -497,7 +497,7 @@ void post_fs_data(int client) { // ack write_int(client, 0); close(client); - if (!check_data()) + if (!is_daemon_init && !check_data()) goto unblock; // Start the debug log diff --git a/core/jni/core/log_monitor.c b/core/jni/core/log_monitor.c index 6808fcffc..55fe677e1 100644 --- a/core/jni/core/log_monitor.c +++ b/core/jni/core/log_monitor.c @@ -82,8 +82,6 @@ static void *logger_thread(void *args) { } static void *magisk_log_thread(void *args) { - int have_data = 0; - // Buffer logs before we have data access struct vector logs; vec_init(&logs); @@ -97,10 +95,12 @@ static void *magisk_log_thread(void *args) { LOGD("log_monitor: magisk log dumper start"); - FILE *log; + FILE *log = NULL; for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) { - if (!have_data) { - if ((have_data = check_data())) { + if (!is_daemon_init) { + vec_push_back(&logs, strdup(line)); + } else { + if (log == NULL) { // Dump buffered logs to file log = xfopen(LOGFILE, "w"); setbuf(log, NULL); @@ -110,12 +110,9 @@ static void *magisk_log_thread(void *args) { free(tmp); } vec_destroy(&logs); - } else { - vec_push_back(&logs, strdup(line)); } - } - if (have_data) fprintf(log, "%s", line); + } } return NULL; } diff --git a/core/jni/utils/misc.c b/core/jni/utils/misc.c index 7306fff40..73fb8094b 100644 --- a/core/jni/utils/misc.c +++ b/core/jni/utils/misc.c @@ -20,6 +20,7 @@ #include "logging.h" #include "utils.h" +#include "resetprop.h" unsigned get_shell_uid() { struct passwd* ppwd = getpwnam("shell"); @@ -46,18 +47,22 @@ 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") == NULL) - ret = 1; + struct vector v; + vec_init(&v); + file_to_vector("/proc/mounts", &v); + char *line, *crypto; + int mnt = 0; + vec_for_each(&v, line) { + if (strstr(line, " /data ")) { + if (strstr(line, "tmpfs") == NULL) + mnt = 1; break; } } - fclose(fp); - return ret; + vec_deep_destroy(&v); + // /data is mounted and not tmpfs and data is unencrypted or vold is started + return mnt && (((crypto = getprop("ro.crypto.state")) && strcmp(crypto, "unencrypted") == 0) + || getprop("init.svc.vold")); } /* All the string should be freed manually!! */