Test logcat instead of checking logd

This commit is contained in:
topjohnwu 2018-04-08 02:12:40 +08:00
parent 7d7686da33
commit 42284c5efb
4 changed files with 24 additions and 23 deletions

View File

@ -15,7 +15,7 @@
#include "resetprop.h"
extern int is_daemon_init;
int logd = 0;
int loggable = 1;
static int am_proc_start_filter(const char *log) {
return strstr(log, "am_proc_start") != NULL;
@ -49,15 +49,16 @@ struct log_listener log_events[] = {
static int debug_log_pid = -1, debug_log_fd = -1;
#endif
static void check_logd() {
char *prop = getprop("init.svc.logd");
if (prop != NULL) {
free(prop);
logd = 1;
} else {
LOGD("log_monitor: logd not started, disable logging");
logd = 0;
static void test_logcat() {
int log_fd = -1, log_pid;
char buf[1];
log_pid = exec_command(0, &log_fd, NULL, "logcat", NULL);
if (read(log_fd, buf, sizeof(buf)) != sizeof(buf)) {
loggable = 0;
LOGD("log_monitor: cannot read from logcat, disable logging");
}
kill(log_pid, SIGTERM);
waitpid(log_pid, NULL, 0);
}
static void *logger_thread(void *args) {
@ -67,7 +68,7 @@ static void *logger_thread(void *args) {
LOGD("log_monitor: logger start");
while (1) {
if (!logd) {
if (!loggable) {
// Disable all services
for (int i = 0; i < (sizeof(log_events) / sizeof(struct log_listener)); ++i) {
close(log_events[i].fd);
@ -98,7 +99,7 @@ static void *logger_thread(void *args) {
// Clear buffer before restart
exec_command_sync("logcat", "-b", "events", "-b", "main", "-c", NULL);
check_logd();
test_logcat();
}
// Should never be here, but well...
@ -163,9 +164,9 @@ static void *debug_magisk_log_thread(void *args) {
void monitor_logs() {
pthread_t thread;
check_logd();
test_logcat();
if (logd) {
if (loggable) {
// Start log file dumper before monitor
xpthread_create(&thread, NULL, magisk_log_thread, NULL);
pthread_detach(thread);
@ -178,7 +179,7 @@ void monitor_logs() {
void start_debug_full_log() {
#ifdef MAGISK_DEBUG
if (logd) {
if (loggable) {
// Log everything initially
debug_log_fd = xopen(DEBUG_LOG, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644);
debug_log_pid = exec_command(0, &debug_log_fd, NULL, "logcat", "-v", "threadtime", NULL);
@ -201,7 +202,7 @@ void stop_debug_full_log() {
void start_debug_log() {
#ifdef MAGISK_DEBUG
if (logd) {
if (loggable) {
pthread_t thread;
// Start debug thread
xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL);

View File

@ -31,7 +31,7 @@ enum {
DAEMON_ERROR = -1,
DAEMON_SUCCESS = 0,
ROOT_REQUIRED,
LOGD_DISABLED,
LOGCAT_DISABLED,
HIDE_IS_ENABLED,
HIDE_NOT_ENABLED,
HIDE_ITEM_EXIST,

View File

@ -58,7 +58,7 @@ struct log_listener {
};
extern struct log_listener log_events[];
extern int logd;
extern int loggable;
void monitor_logs();
void start_debug_full_log();

View File

@ -49,9 +49,9 @@ void launch_magiskhide(int client) {
return;
}
if (!logd) {
if (!loggable) {
if (client > 0) {
write_int(client, LOGD_DISABLED);
write_int(client, LOGCAT_DISABLED);
close(client);
}
setprop(MAGISKHIDE_PROP, "0");
@ -147,14 +147,14 @@ int magiskhide_main(int argc, char *argv[]) {
case ROOT_REQUIRED:
fprintf(stderr, "Root is required for this operation\n");
return code;
case LOGD_DISABLED:
fprintf(stderr, "Logd is not running, cannot run logcat\n");
case LOGCAT_DISABLED:
fprintf(stderr, "Logcat is disabled, cannot start MagiskHide\n");
return (code);
case HIDE_NOT_ENABLED:
fprintf(stderr, "Magisk hide is not enabled yet\n");
fprintf(stderr, "MagiskHide is not enabled yet\n");
return code;
case HIDE_IS_ENABLED:
fprintf(stderr, "Magisk hide is already enabled\n");
fprintf(stderr, "MagiskHide is already enabled\n");
return code;
case HIDE_ITEM_EXIST:
fprintf(stderr, "Process [%s] already exists in hide list\n", argv[2]);