2017-04-04 19:44:13 +00: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-14 19:23:09 +00:00
|
|
|
#include <limits.h>
|
2017-04-04 19:44:13 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2017-04-05 22:12:29 +00:00
|
|
|
#include "magisk.h"
|
2017-04-04 19:44:13 +00:00
|
|
|
#include "utils.h"
|
2017-04-14 19:23:09 +00:00
|
|
|
#include "daemon.h"
|
2017-04-04 19:44:13 +00:00
|
|
|
|
|
|
|
static void *logger_thread(void *args) {
|
2017-04-14 19:23:09 +00:00
|
|
|
char buffer[PATH_MAX];
|
2017-04-17 08:36:49 +00:00
|
|
|
xrename("/cache/magisk.log", "/cache/last_magisk.log");
|
2017-04-15 18:42:24 +00:00
|
|
|
FILE *logfile = xfopen("/cache/magisk.log", "w");
|
2017-04-04 19:44:13 +00:00
|
|
|
// Disable buffering
|
|
|
|
setbuf(logfile, NULL);
|
|
|
|
// Start logcat
|
2017-04-17 08:36:49 +00:00
|
|
|
FILE *log_monitor = popen("logcat -s Magisk -v time", "r");
|
|
|
|
while (fgets(buffer, sizeof(buffer), log_monitor)) {
|
2017-04-14 19:23:09 +00:00
|
|
|
fprintf(logfile, "%s", buffer);
|
2017-04-04 19:44:13 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-05 22:12:29 +00:00
|
|
|
/* Start a new thread to monitor logcat and dump to logfile */
|
2017-04-04 19:44:13 +00:00
|
|
|
void monitor_logs() {
|
2017-04-17 08:36:49 +00:00
|
|
|
pthread_t log_monitor_thread;
|
|
|
|
pthread_create(&log_monitor_thread, NULL, logger_thread, NULL);
|
|
|
|
}
|