2017-04-05 03:44:13 +08:00
|
|
|
/* log_monitor.c - New thread to monitor logcat
|
|
|
|
*
|
|
|
|
* Open a new thread to call logcat and get logs with tag "Magisk"
|
|
|
|
* Also, write the logs to a log file for debugging purpose
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2017-04-15 03:23:09 +08:00
|
|
|
#include <limits.h>
|
2017-04-05 03:44:13 +08:00
|
|
|
#include <pthread.h>
|
2017-05-08 03:11:14 +08:00
|
|
|
#include <unistd.h>
|
2017-06-03 04:31:01 +08:00
|
|
|
#include <sys/wait.h>
|
2017-04-05 03:44:13 +08:00
|
|
|
|
2017-04-06 06:12:29 +08:00
|
|
|
#include "magisk.h"
|
2017-04-05 03:44:13 +08:00
|
|
|
#include "utils.h"
|
2017-04-15 03:23:09 +08:00
|
|
|
#include "daemon.h"
|
2017-04-05 03:44:13 +08:00
|
|
|
|
|
|
|
static void *logger_thread(void *args) {
|
2017-04-22 06:33:40 +08:00
|
|
|
// Setup error handler
|
|
|
|
err_handler = exit_thread;
|
|
|
|
|
2017-05-04 01:13:04 +08:00
|
|
|
rename(LOGFILE, LASTLOG);
|
2017-06-08 03:20:49 +08:00
|
|
|
int log_fd, log_pid;
|
|
|
|
|
|
|
|
log_fd = xopen(LOGFILE, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644);
|
2017-06-03 04:31:01 +08:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// Start logcat
|
2017-06-08 03:20:49 +08:00
|
|
|
char *const command[] = { "logcat", "-s", "Magisk", "-v", "thread", NULL };
|
|
|
|
log_pid = run_command(0, &log_fd, "/system/bin/logcat", command);
|
2017-06-03 04:31:01 +08:00
|
|
|
waitpid(log_pid, NULL, 0);
|
2017-06-08 03:20:49 +08:00
|
|
|
// For some reason it went here, clear buffer and restart
|
2017-06-03 04:31:01 +08:00
|
|
|
system("logcat -c");
|
2017-04-05 03:44:13 +08:00
|
|
|
}
|
2017-06-03 04:31:01 +08:00
|
|
|
|
2017-05-08 03:11:14 +08:00
|
|
|
// Should never be here, but well...
|
2017-06-08 03:20:49 +08:00
|
|
|
close(log_fd);
|
2017-04-05 03:44:13 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-06 06:12:29 +08:00
|
|
|
/* Start a new thread to monitor logcat and dump to logfile */
|
2017-04-05 03:44:13 +08:00
|
|
|
void monitor_logs() {
|
2017-06-08 03:20:49 +08:00
|
|
|
pthread_t thread;
|
|
|
|
xpthread_create(&thread, NULL, logger_thread, NULL);
|
|
|
|
pthread_detach(thread);
|
2017-04-17 16:36:49 +08:00
|
|
|
}
|