Move Android logging out of libutils

This commit is contained in:
topjohnwu 2020-05-10 00:48:41 -07:00
parent 0f8f4e361b
commit 122b4d66b6
3 changed files with 27 additions and 49 deletions

View File

@ -1,13 +1,11 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <pthread.h>
#include <signal.h>
#include <libgen.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <android/log.h>
#include <magisk.hpp>
#include <utils.hpp>
@ -112,6 +110,19 @@ static void *request_handler(void *args) {
return nullptr;
}
static void android_logging() {
static constexpr char TAG[] = "Magisk";
#ifdef MAGISK_DEBUG
log_cb.d = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_DEBUG, TAG, fmt, ap); };
#else
log_cb.d = nop_log;
#endif
log_cb.i = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_INFO, TAG, fmt, ap); };
log_cb.w = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_WARN, TAG, fmt, ap); };
log_cb.e = [](auto fmt, auto ap){ return __android_log_vprint(ANDROID_LOG_ERROR, TAG, fmt, ap); };
log_cb.ex = nop_ex;
}
static void daemon_entry(int ppid) {
android_logging();

View File

@ -33,7 +33,6 @@ int nop_log(const char *fmt, va_list ap);
void nop_ex(int i);
void no_logging();
void android_logging();
void cmdline_logging();
int log_handler(log_type t, const char *fmt, ...);

View File

@ -1,9 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <android/log.h>
#include <logging.hpp>
#include <flags.h>
int nop_log(const char *fmt, va_list ap) {
return 0;
@ -27,36 +25,6 @@ void no_logging() {
log_cb.ex = nop_ex;
}
#define LOG_TAG "Magisk"
[[maybe_unused]] static int log_d(const char *fmt, va_list ap) {
return __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ap);
}
static int log_i(const char *fmt, va_list ap) {
return __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, fmt, ap);
}
static int log_w(const char *fmt, va_list ap) {
return __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, fmt, ap);
}
static int log_e(const char *fmt, va_list ap) {
return __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, fmt, ap);
}
void android_logging() {
#ifdef MAGISK_DEBUG
log_cb.d = log_d;
#else
log_cb.d = nop_log;
#endif
log_cb.i = log_i;
log_cb.w = log_w;
log_cb.e = log_e;
log_cb.ex = nop_ex;
}
static int vprinte(const char *fmt, va_list ap) {
return vfprintf(stderr, fmt, ap);
}
@ -74,19 +42,19 @@ int log_handler(log_type t, const char *fmt, ...) {
int ret = 0;
va_start(argv, fmt);
switch (t) {
case L_DEBUG:
ret = log_cb.d(fmt, argv);
break;
case L_INFO:
ret = log_cb.i(fmt, argv);
break;
case L_WARN:
ret = log_cb.w(fmt, argv);
break;
case L_ERR:
ret = log_cb.e(fmt, argv);
log_cb.ex(1);
break;
case L_DEBUG:
ret = log_cb.d(fmt, argv);
break;
case L_INFO:
ret = log_cb.i(fmt, argv);
break;
case L_WARN:
ret = log_cb.w(fmt, argv);
break;
case L_ERR:
ret = log_cb.e(fmt, argv);
log_cb.ex(1);
break;
}
va_end(argv);
return ret;