Connect to magiskd log daemon

This commit is contained in:
topjohnwu
2021-08-21 03:52:59 -07:00
parent bade4f2c6a
commit 171d68ca72
7 changed files with 163 additions and 39 deletions

View File

@@ -10,6 +10,7 @@ void unlock_blocks();
void reboot();
void start_log_daemon();
void setup_logfile(bool reset);
void magisk_logging();
// Module stuffs
void handle_modules();

View File

@@ -17,7 +17,7 @@ struct log_meta {
int tid;
};
static atomic<int> logd_fd = -1;
atomic<int> logd_fd = -1;
void setup_logfile(bool reset) {
if (logd_fd < 0)
@@ -121,7 +121,7 @@ static void logfile_writer(int pipefd) {
}
}
static int magisk_log(int prio, const char *fmt, va_list ap) {
int magisk_log(int prio, const char *fmt, va_list ap) {
char buf[MAX_MSG_LEN + 1];
int len = vsnprintf(buf, sizeof(buf), fmt, ap);
@@ -172,6 +172,15 @@ void magisk_logging() {
log_cb.ex = nop_ex;
}
#define alog(prio) [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_##prio, "Magisk", fmt, ap); }
void android_logging() {
log_cb.d = alog(DEBUG);
log_cb.i = alog(INFO);
log_cb.w = alog(WARN);
log_cb.e = alog(ERROR);
log_cb.ex = nop_ex;
}
void start_log_daemon() {
int fds[2];
if (pipe2(fds, O_CLOEXEC) == 0) {