mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Check logd before logging
This commit is contained in:
parent
bd7766b17e
commit
754fafcfe9
@ -265,6 +265,9 @@ void start_daemon() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
xlisten(fd, 10);
|
xlisten(fd, 10);
|
||||||
|
|
||||||
|
// Start the log monitor
|
||||||
|
monitor_logs();
|
||||||
|
|
||||||
if ((is_daemon_init = (access(MAGISKTMP, F_OK) == 0))) {
|
if ((is_daemon_init = (access(MAGISKTMP, F_OK) == 0))) {
|
||||||
// Restart stuffs if the daemon is restarted
|
// Restart stuffs if the daemon is restarted
|
||||||
exec_command_sync("logcat", "-b", "all", "-c", NULL);
|
exec_command_sync("logcat", "-b", "all", "-c", NULL);
|
||||||
@ -274,9 +277,6 @@ void start_daemon() {
|
|||||||
daemon_init();
|
daemon_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the log monitor
|
|
||||||
monitor_logs();
|
|
||||||
|
|
||||||
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n");
|
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n");
|
||||||
|
|
||||||
// Change process name
|
// Change process name
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
|
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "resetprop.h"
|
||||||
|
|
||||||
extern int is_daemon_init;
|
extern int is_daemon_init;
|
||||||
|
int logd = 0;
|
||||||
|
|
||||||
static int am_proc_start_filter(const char *log) {
|
static int am_proc_start_filter(const char *log) {
|
||||||
return strstr(log, "am_proc_start") != NULL;
|
return strstr(log, "am_proc_start") != NULL;
|
||||||
@ -44,9 +46,20 @@ struct log_listener log_events[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MAGISK_DEBUG
|
#ifdef MAGISK_DEBUG
|
||||||
static int debug_log_pid, debug_log_fd;
|
static int debug_log_pid = -1, debug_log_fd = -1;
|
||||||
#endif
|
#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 *logger_thread(void *args) {
|
static void *logger_thread(void *args) {
|
||||||
int log_fd = -1, log_pid;
|
int log_fd = -1, log_pid;
|
||||||
char line[4096];
|
char line[4096];
|
||||||
@ -54,6 +67,15 @@ static void *logger_thread(void *args) {
|
|||||||
LOGD("log_monitor: logger start");
|
LOGD("log_monitor: logger start");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (!logd) {
|
||||||
|
// Disable all services
|
||||||
|
for (int i = 0; i < (sizeof(log_events) / sizeof(struct log_listener)); ++i) {
|
||||||
|
close(log_events[i].fd);
|
||||||
|
log_events[i].fd = -1;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Start logcat
|
// Start logcat
|
||||||
log_pid = exec_command(0, &log_fd, NULL, "logcat", "-b", "events", "-b", "main", "-v", "threadtime", "-s", "am_proc_start", "-s", "Magisk", NULL);
|
log_pid = exec_command(0, &log_fd, NULL, "logcat", "-b", "events", "-b", "main", "-v", "threadtime", "-s", "am_proc_start", "-s", "Magisk", NULL);
|
||||||
while (fdgets(line, sizeof(line), log_fd)) {
|
while (fdgets(line, sizeof(line), log_fd)) {
|
||||||
@ -75,6 +97,8 @@ static void *logger_thread(void *args) {
|
|||||||
|
|
||||||
// Clear buffer before restart
|
// Clear buffer before restart
|
||||||
exec_command_sync("logcat", "-b", "events", "-b", "main", "-c", NULL);
|
exec_command_sync("logcat", "-b", "events", "-b", "main", "-c", NULL);
|
||||||
|
|
||||||
|
check_logd();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should never be here, but well...
|
// Should never be here, but well...
|
||||||
@ -139,40 +163,49 @@ static void *debug_magisk_log_thread(void *args) {
|
|||||||
void monitor_logs() {
|
void monitor_logs() {
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
// Start log file dumper before monitor
|
check_logd();
|
||||||
xpthread_create(&thread, NULL, magisk_log_thread, NULL);
|
|
||||||
pthread_detach(thread);
|
|
||||||
|
|
||||||
// Start logcat monitor
|
if (logd) {
|
||||||
xpthread_create(&thread, NULL, logger_thread, NULL);
|
// Start log file dumper before monitor
|
||||||
pthread_detach(thread);
|
xpthread_create(&thread, NULL, magisk_log_thread, NULL);
|
||||||
|
pthread_detach(thread);
|
||||||
|
|
||||||
|
// Start logcat monitor
|
||||||
|
xpthread_create(&thread, NULL, logger_thread, NULL);
|
||||||
|
pthread_detach(thread);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_debug_full_log() {
|
void start_debug_full_log() {
|
||||||
#ifdef MAGISK_DEBUG
|
#ifdef MAGISK_DEBUG
|
||||||
// Log everything initially
|
if (logd) {
|
||||||
debug_log_fd = xopen(DEBUG_LOG, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644);
|
// Log everything initially
|
||||||
debug_log_pid = exec_command(0, &debug_log_fd, NULL, "logcat", "-v", "threadtime", NULL);
|
debug_log_fd = xopen(DEBUG_LOG, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644);
|
||||||
close(debug_log_fd);
|
debug_log_pid = exec_command(0, &debug_log_fd, NULL, "logcat", "-v", "threadtime", NULL);
|
||||||
|
close(debug_log_fd);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_debug_full_log() {
|
void stop_debug_full_log() {
|
||||||
#ifdef MAGISK_DEBUG
|
#ifdef MAGISK_DEBUG
|
||||||
// Stop recording the boot logcat after every boot task is done
|
// Stop recording the boot logcat after every boot task is done
|
||||||
kill(debug_log_pid, SIGTERM);
|
if (debug_log_pid > 0) {
|
||||||
waitpid(debug_log_pid, NULL, 0);
|
kill(debug_log_pid, SIGTERM);
|
||||||
// Start debug thread
|
waitpid(debug_log_pid, NULL, 0);
|
||||||
start_debug_log();
|
// Start debug thread
|
||||||
|
start_debug_log();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_debug_log() {
|
void start_debug_log() {
|
||||||
#ifdef MAGISK_DEBUG
|
#ifdef MAGISK_DEBUG
|
||||||
pthread_t thread;
|
if (logd) {
|
||||||
// Start debug thread
|
pthread_t thread;
|
||||||
xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL);
|
// Start debug thread
|
||||||
pthread_detach(thread);
|
xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL);
|
||||||
|
pthread_detach(thread);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,17 @@ extern int is_daemon_init, seperate_vendor;
|
|||||||
// Commands require connecting to daemon
|
// Commands require connecting to daemon
|
||||||
enum {
|
enum {
|
||||||
DO_NOTHING = 0,
|
DO_NOTHING = 0,
|
||||||
LAUNCH_MAGISKHIDE,
|
|
||||||
STOP_MAGISKHIDE,
|
|
||||||
ADD_HIDELIST,
|
|
||||||
RM_HIDELIST,
|
|
||||||
LS_HIDELIST,
|
|
||||||
SUPERUSER,
|
SUPERUSER,
|
||||||
CHECK_VERSION,
|
CHECK_VERSION,
|
||||||
CHECK_VERSION_CODE,
|
CHECK_VERSION_CODE,
|
||||||
POST_FS,
|
POST_FS,
|
||||||
POST_FS_DATA,
|
POST_FS_DATA,
|
||||||
LATE_START,
|
LATE_START,
|
||||||
TEST
|
LAUNCH_MAGISKHIDE,
|
||||||
|
STOP_MAGISKHIDE,
|
||||||
|
ADD_HIDELIST,
|
||||||
|
RM_HIDELIST,
|
||||||
|
LS_HIDELIST
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return codes for daemon
|
// Return codes for daemon
|
||||||
@ -32,6 +31,7 @@ enum {
|
|||||||
DAEMON_ERROR = -1,
|
DAEMON_ERROR = -1,
|
||||||
DAEMON_SUCCESS = 0,
|
DAEMON_SUCCESS = 0,
|
||||||
ROOT_REQUIRED,
|
ROOT_REQUIRED,
|
||||||
|
LOGD_DISABLED,
|
||||||
HIDE_IS_ENABLED,
|
HIDE_IS_ENABLED,
|
||||||
HIDE_NOT_ENABLED,
|
HIDE_NOT_ENABLED,
|
||||||
HIDE_ITEM_EXIST,
|
HIDE_ITEM_EXIST,
|
||||||
|
@ -58,6 +58,7 @@ struct log_listener {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern struct log_listener log_events[];
|
extern struct log_listener log_events[];
|
||||||
|
extern int logd;
|
||||||
|
|
||||||
void monitor_logs();
|
void monitor_logs();
|
||||||
void start_debug_full_log();
|
void start_debug_full_log();
|
||||||
|
@ -49,6 +49,14 @@ void launch_magiskhide(int client) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!logd) {
|
||||||
|
if (client > 0) {
|
||||||
|
write_int(client, LOGD_DISABLED);
|
||||||
|
close(client);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hideEnabled = 1;
|
hideEnabled = 1;
|
||||||
LOGI("* Starting MagiskHide\n");
|
LOGI("* Starting MagiskHide\n");
|
||||||
|
|
||||||
@ -136,6 +144,9 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
case ROOT_REQUIRED:
|
case ROOT_REQUIRED:
|
||||||
fprintf(stderr, "Root is required for this operation\n");
|
fprintf(stderr, "Root is required for this operation\n");
|
||||||
return code;
|
return code;
|
||||||
|
case LOGD_DISABLED:
|
||||||
|
fprintf(stderr, "Logd is not running, cannot run logcat\n");
|
||||||
|
return (code);
|
||||||
case HIDE_NOT_ENABLED:
|
case HIDE_NOT_ENABLED:
|
||||||
fprintf(stderr, "Magisk hide is not enabled yet\n");
|
fprintf(stderr, "Magisk hide is not enabled yet\n");
|
||||||
return code;
|
return code;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user