mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-07 16:09:44 +00:00
Add excessive logging for debug mode
This commit is contained in:
@@ -172,7 +172,7 @@ void exec_common_script(const char* stage) {
|
||||
continue;
|
||||
LOGI("%s.d: exec [%s]\n", stage, entry->d_name);
|
||||
char *const command[] = { "sh", buf2, NULL };
|
||||
int pid = run_command(NULL, "/system/bin/sh", command);
|
||||
int pid = run_command(0, NULL, "/system/bin/sh", command);
|
||||
if (pid != -1)
|
||||
waitpid(pid, NULL, 0);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ void exec_module_script(const char* stage) {
|
||||
continue;
|
||||
LOGI("%s: exec [%s.sh]\n", module, stage);
|
||||
char *const command[] = { "sh", buf, NULL };
|
||||
int pid = run_command(NULL, "/system/bin/sh", command);
|
||||
int pid = run_command(0, NULL, "/system/bin/sh", command);
|
||||
if (pid != -1)
|
||||
waitpid(pid, NULL, 0);
|
||||
}
|
||||
@@ -458,6 +458,10 @@ static void unblock_boot_process() {
|
||||
void post_fs(int client) {
|
||||
// Error handler
|
||||
err_handler = unblock_boot_process;
|
||||
|
||||
// Start log monitor
|
||||
monitor_logs();
|
||||
|
||||
LOGI("** post-fs mode running\n");
|
||||
// ack
|
||||
write_int(client, 0);
|
||||
@@ -730,8 +734,8 @@ void late_start(int client) {
|
||||
"CLASSPATH=/system/framework/pm.jar "
|
||||
"/system/bin/app_process /system/bin "
|
||||
"com.android.commands.pm.Pm install -r " MANAGERAPK, NULL };
|
||||
int apk_res, pid;
|
||||
pid = run_command(&apk_res, "/system/bin/sh", command);
|
||||
int apk_res = 0, pid;
|
||||
pid = run_command(1, &apk_res, "/system/bin/sh", command);
|
||||
waitpid(pid, NULL, 0);
|
||||
fdgets(buf, PATH_MAX, apk_res);
|
||||
close(apk_res);
|
||||
@@ -746,4 +750,12 @@ void late_start(int client) {
|
||||
free(buf);
|
||||
free(buf2);
|
||||
vec_deep_destroy(&module_list);
|
||||
|
||||
#ifdef DEBUG
|
||||
// Stop recording the boot logcat after every boot task is done
|
||||
extern int debug_log_pid, debug_log_fd;
|
||||
kill(debug_log_pid, SIGTERM);
|
||||
waitpid(debug_log_pid, NULL, 0);
|
||||
close(debug_log_fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -162,9 +162,6 @@ void start_daemon(int client) {
|
||||
// It should stay intact under any circumstances
|
||||
err_handler = do_nothing;
|
||||
|
||||
// Start log monitor
|
||||
monitor_logs();
|
||||
|
||||
LOGI("Magisk v" xstr(MAGISK_VERSION) " daemon started\n");
|
||||
|
||||
// Unlock all blocks for rw
|
||||
@@ -174,7 +171,7 @@ void start_daemon(int client) {
|
||||
xmount(NULL, "/", NULL, MS_REMOUNT, NULL);
|
||||
create_links(NULL, "/sbin");
|
||||
xchmod("/sbin", 0755);
|
||||
xmkdir("/magisk", 0755);
|
||||
mkdir("/magisk", 0755);
|
||||
xchmod("/magisk", 0755);
|
||||
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
|
||||
|
||||
|
||||
@@ -15,41 +15,43 @@
|
||||
#include "utils.h"
|
||||
#include "daemon.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
int debug_log_pid, debug_log_fd;
|
||||
#endif
|
||||
|
||||
static void *logger_thread(void *args) {
|
||||
// Setup error handler
|
||||
err_handler = exit_thread;
|
||||
|
||||
char *buffer = xmalloc(PATH_MAX);
|
||||
rename(LOGFILE, LASTLOG);
|
||||
FILE *logfile = xfdopen(xopen(LOGFILE, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644), "w");
|
||||
// Disable buffering
|
||||
setbuf(logfile, NULL);
|
||||
int fd, log_pid;
|
||||
int log_fd, log_pid;
|
||||
|
||||
log_fd = xopen(LOGFILE, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644);
|
||||
|
||||
while (1) {
|
||||
// Start logcat
|
||||
char *const command[] = { "logcat", "-s", "Magisk", "-v", "time", NULL };
|
||||
log_pid = run_command(&fd, "/system/bin/logcat", command);
|
||||
while (fdgets(buffer, PATH_MAX, fd)) {
|
||||
fprintf(logfile, "%s", buffer);
|
||||
}
|
||||
|
||||
// For some reason it went here, clear buffer and restart
|
||||
close(fd);
|
||||
kill(log_pid, SIGTERM);
|
||||
char *const command[] = { "logcat", "-s", "Magisk", "-v", "thread", NULL };
|
||||
log_pid = run_command(0, &log_fd, "/system/bin/logcat", command);
|
||||
waitpid(log_pid, NULL, 0);
|
||||
// For some reason it went here, clear buffer and restart
|
||||
system("logcat -c");
|
||||
}
|
||||
|
||||
// Should never be here, but well...
|
||||
fclose(logfile);
|
||||
free(buffer);
|
||||
close(log_fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Start a new thread to monitor logcat and dump to logfile */
|
||||
void monitor_logs() {
|
||||
pthread_t log_monitor_thread;
|
||||
xpthread_create(&log_monitor_thread, NULL, logger_thread, NULL);
|
||||
pthread_detach(log_monitor_thread);
|
||||
pthread_t thread;
|
||||
xpthread_create(&thread, NULL, logger_thread, NULL);
|
||||
pthread_detach(thread);
|
||||
|
||||
#ifdef DEBUG
|
||||
// Start debug logs in new process
|
||||
debug_log_fd = xopen(DEBUG_LOG, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644);
|
||||
char *const command[] = { "logcat", "-v", "brief", NULL };
|
||||
debug_log_pid = run_command(0, &debug_log_fd, "/system/bin/logcat", command);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user