Properly detect /data status

This commit is contained in:
topjohnwu 2017-12-23 04:58:51 +08:00
parent b92b1dcddb
commit 022b18c8ce
3 changed files with 21 additions and 19 deletions

View File

@ -497,7 +497,7 @@ void post_fs_data(int client) {
// ack // ack
write_int(client, 0); write_int(client, 0);
close(client); close(client);
if (!check_data()) if (!is_daemon_init && !check_data())
goto unblock; goto unblock;
// Start the debug log // Start the debug log

View File

@ -82,8 +82,6 @@ static void *logger_thread(void *args) {
} }
static void *magisk_log_thread(void *args) { static void *magisk_log_thread(void *args) {
int have_data = 0;
// Buffer logs before we have data access // Buffer logs before we have data access
struct vector logs; struct vector logs;
vec_init(&logs); vec_init(&logs);
@ -97,10 +95,12 @@ static void *magisk_log_thread(void *args) {
LOGD("log_monitor: magisk log dumper start"); LOGD("log_monitor: magisk log dumper start");
FILE *log; FILE *log = NULL;
for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) { for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) {
if (!have_data) { if (!is_daemon_init) {
if ((have_data = check_data())) { vec_push_back(&logs, strdup(line));
} else {
if (log == NULL) {
// Dump buffered logs to file // Dump buffered logs to file
log = xfopen(LOGFILE, "w"); log = xfopen(LOGFILE, "w");
setbuf(log, NULL); setbuf(log, NULL);
@ -110,12 +110,9 @@ static void *magisk_log_thread(void *args) {
free(tmp); free(tmp);
} }
vec_destroy(&logs); vec_destroy(&logs);
} else {
vec_push_back(&logs, strdup(line));
} }
}
if (have_data)
fprintf(log, "%s", line); fprintf(log, "%s", line);
}
} }
return NULL; return NULL;
} }

View File

@ -20,6 +20,7 @@
#include "logging.h" #include "logging.h"
#include "utils.h" #include "utils.h"
#include "resetprop.h"
unsigned get_shell_uid() { unsigned get_shell_uid() {
struct passwd* ppwd = getpwnam("shell"); struct passwd* ppwd = getpwnam("shell");
@ -46,18 +47,22 @@ unsigned get_radio_uid() {
} }
int check_data() { int check_data() {
int ret = 0; struct vector v;
char buffer[4096]; vec_init(&v);
FILE *fp = xfopen("/proc/mounts", "r"); file_to_vector("/proc/mounts", &v);
while (fgets(buffer, sizeof(buffer), fp)) { char *line, *crypto;
if (strstr(buffer, " /data ")) { int mnt = 0;
if (strstr(buffer, "tmpfs") == NULL) vec_for_each(&v, line) {
ret = 1; if (strstr(line, " /data ")) {
if (strstr(line, "tmpfs") == NULL)
mnt = 1;
break; break;
} }
} }
fclose(fp); vec_deep_destroy(&v);
return ret; // /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!! */ /* All the string should be freed manually!! */