Fix magiskinit invincible mode and logcat monitor

This commit is contained in:
topjohnwu 2017-12-18 02:51:27 +08:00
parent 17f0fea3fc
commit d065040321
4 changed files with 17 additions and 11 deletions

View File

@ -262,9 +262,6 @@ void start_daemon() {
exit(1);
xlisten(fd, 10);
// Start the log monitor
monitor_logs();
if ((is_daemon_init = (access(MAGISKTMP, F_OK) == 0))) {
// Restart stuffs if the daemon is restarted
exec_command_sync("logcat", "-b", "all", "-c", NULL);
@ -274,6 +271,9 @@ void start_daemon() {
daemon_init();
}
// Start the log monitor
monitor_logs();
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n");
// Change process name

View File

@ -39,7 +39,14 @@ static void *logger_thread(void *args) {
if (kill(log_pid, 0))
break;
}
// Clear buffer if restart required
// Cleanup
close(log_fd);
log_fd = -1;
kill(log_pid, SIGTERM);
waitpid(log_pid, NULL, 0);
// Clear buffer before restart
exec_command_sync("logcat", "-b", "all", "-c", NULL);
}
@ -54,7 +61,6 @@ static void *magisk_log_thread(void *args) {
struct vector logs;
vec_init(&logs);
FILE *log;
int pipefd[2];
if (xpipe2(pipefd, O_CLOEXEC) == -1)
return NULL;
@ -64,14 +70,14 @@ static void *magisk_log_thread(void *args) {
LOGD("log_monitor: magisk log dumper start");
FILE *log;
char *ss;
for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) {
char *ss;
if ((ss = strstr(line, " Magisk")) && (ss[-1] != 'D') && (ss[-1] != 'V')) {
if (!have_data) {
if ((have_data = check_data())) {
// Dump buffered logs to file
rename(LOGFILE, LASTLOG);
log = xfopen(LOGFILE, "a");
log = xfopen(LOGFILE, "w");
setbuf(log, NULL);
char *tmp;
vec_for_each(&logs, tmp) {

View File

@ -380,9 +380,9 @@ static void magisk_init_daemon() {
destroy_policydb();
// Keep Magisk daemon always alive
struct sockaddr_un sun;
fd = setup_socket(&sun);
while (1) {
struct sockaddr_un sun;
fd = setup_socket(&sun);
while (connect(fd, (struct sockaddr*) &sun, sizeof(sun)))
usleep(10000); /* Wait 10 ms after each try */
@ -391,6 +391,7 @@ static void magisk_init_daemon() {
/* If things went here, it means the other side of the socket is closed
* We restart the daemon again */
close(fd);
if (fork_dont_care() == 0) {
execv("/sbin/magisk", (char *[]) { "resetprop", "magisk.daemon", "1", NULL } );
exit(1);

View File

@ -14,7 +14,6 @@
#endif
#define LOGFILE "/cache/magisk.log"
#define LASTLOG "/cache/last_magisk.log"
#define DEBUG_LOG "/data/adb/magisk_debug.log"
#define UNBLOCKFILE "/dev/.magisk.unblock"
#define PATCHDONE "/dev/.magisk.patch.done"