mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 13:17:39 +02:00
Make xhook log as Magisk
This commit is contained in:
@ -8,7 +8,6 @@ extern int DAEMON_STATE;
|
||||
|
||||
void unlock_blocks();
|
||||
void reboot();
|
||||
void magisk_logging();
|
||||
void start_log_daemon();
|
||||
void setup_logfile(bool reset);
|
||||
|
||||
|
@ -149,6 +149,20 @@ static int magisk_log(int prio, const char *fmt, va_list ap) {
|
||||
return len;
|
||||
}
|
||||
|
||||
// Used to override external C library logging
|
||||
extern "C" int magisk_log_print(int prio, const char *tag, const char *fmt, ...) {
|
||||
char buf[4096];
|
||||
auto len = strlcpy(buf, tag, sizeof(buf));
|
||||
// Prevent format specifications in the tag
|
||||
std::replace(buf, buf + len, '%', '_');
|
||||
snprintf(buf + len, sizeof(buf) - len, ": %s", fmt);
|
||||
va_list argv;
|
||||
va_start(argv, fmt);
|
||||
int ret = magisk_log(prio, buf, argv);
|
||||
va_end(argv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define mlog(prio) [](auto fmt, auto ap){ return magisk_log(ANDROID_LOG_##prio, fmt, ap); }
|
||||
void magisk_logging() {
|
||||
log_cb.d = mlog(DEBUG);
|
||||
@ -158,16 +172,6 @@ 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) {
|
||||
|
Reference in New Issue
Block a user