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
write_int(client, 0);
close(client);
if (!check_data())
if (!is_daemon_init && !check_data())
goto unblock;
// Start the debug log

View File

@ -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,13 +110,10 @@ 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;
}

View File

@ -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!! */