Update collect log logic
This commit is contained in:
parent
3733b589ac
commit
0f8f4e361b
@ -189,18 +189,23 @@ void unlock_blocks() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool log_dump = false;
|
static void collect_logs(bool reset) {
|
||||||
static void dump_logs() {
|
static bool running = false;
|
||||||
if (log_dump)
|
static pthread_mutex_t log_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
return;
|
{
|
||||||
int test = exec_command_sync("/system/bin/logcat", "-d", "-f", "/dev/null");
|
mutex_guard lock(log_lock);
|
||||||
chmod("/dev/null", 0666);
|
if (running)
|
||||||
if (test != 0)
|
return;
|
||||||
return;
|
int test = exec_command_sync("/system/bin/logcat", "-d", "-f", "/dev/null");
|
||||||
rename(LOGFILE, LOGFILE ".bak");
|
chmod("/dev/null", 0666);
|
||||||
log_dump = true;
|
if (test != 0)
|
||||||
|
return;
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
if (reset)
|
||||||
|
rename(LOGFILE, LOGFILE ".bak");
|
||||||
// Start a daemon thread and wait indefinitely
|
// Start a daemon thread and wait indefinitely
|
||||||
new_daemon_thread([]() -> void {
|
new_daemon_thread([]{
|
||||||
int fd = xopen(LOGFILE, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
|
int fd = xopen(LOGFILE, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
|
||||||
exec_t exec {
|
exec_t exec {
|
||||||
.fd = fd,
|
.fd = fd,
|
||||||
@ -209,7 +214,8 @@ static void dump_logs() {
|
|||||||
int pid = exec_command(exec, "/system/bin/logcat", "-s", "Magisk");
|
int pid = exec_command(exec, "/system/bin/logcat", "-s", "Magisk");
|
||||||
close(fd);
|
close(fd);
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
log_dump = false;
|
mutex_guard lock(log_lock);
|
||||||
|
running = false;
|
||||||
} else {
|
} else {
|
||||||
waitpid(pid, nullptr, 0);
|
waitpid(pid, nullptr, 0);
|
||||||
}
|
}
|
||||||
@ -220,7 +226,7 @@ static void dump_logs() {
|
|||||||
* Entry points *
|
* Entry points *
|
||||||
****************/
|
****************/
|
||||||
|
|
||||||
[[noreturn]] static void unblock_boot_process() {
|
[[noreturn]] static void exit_post_fs_data() {
|
||||||
close(xopen(UNBLOCKFILE, O_RDONLY | O_CREAT, 0));
|
close(xopen(UNBLOCKFILE, O_RDONLY | O_CREAT, 0));
|
||||||
pthread_exit(nullptr);
|
pthread_exit(nullptr);
|
||||||
}
|
}
|
||||||
@ -234,9 +240,9 @@ void post_fs_data(int client) {
|
|||||||
xmount(nullptr, "/", nullptr, MS_REMOUNT | MS_RDONLY, nullptr);
|
xmount(nullptr, "/", nullptr, MS_REMOUNT | MS_RDONLY, nullptr);
|
||||||
|
|
||||||
if (!check_data())
|
if (!check_data())
|
||||||
unblock_boot_process();
|
exit_post_fs_data();
|
||||||
|
|
||||||
dump_logs();
|
collect_logs(true);
|
||||||
|
|
||||||
LOGI("** post-fs-data mode running\n");
|
LOGI("** post-fs-data mode running\n");
|
||||||
|
|
||||||
@ -249,12 +255,12 @@ void post_fs_data(int client) {
|
|||||||
* will cause bootloops on FBE devices. */
|
* will cause bootloops on FBE devices. */
|
||||||
LOGE(SECURE_DIR " is not present, abort...");
|
LOGE(SECURE_DIR " is not present, abort...");
|
||||||
no_secure_dir = true;
|
no_secure_dir = true;
|
||||||
unblock_boot_process();
|
exit_post_fs_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!magisk_env()) {
|
if (!magisk_env()) {
|
||||||
LOGE("* Magisk environment setup incomplete, abort\n");
|
LOGE("* Magisk environment setup incomplete, abort\n");
|
||||||
unblock_boot_process();
|
exit_post_fs_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getprop("persist.sys.safemode", true) == "1") {
|
if (getprop("persist.sys.safemode", true) == "1") {
|
||||||
@ -272,7 +278,7 @@ void post_fs_data(int client) {
|
|||||||
// We still want to do magic mount because root itself might need it
|
// We still want to do magic mount because root itself might need it
|
||||||
magic_mount();
|
magic_mount();
|
||||||
pfs_done = true;
|
pfs_done = true;
|
||||||
unblock_boot_process();
|
exit_post_fs_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void late_start(int client) {
|
void late_start(int client) {
|
||||||
@ -281,7 +287,7 @@ void late_start(int client) {
|
|||||||
write_int(client, 0);
|
write_int(client, 0);
|
||||||
close(client);
|
close(client);
|
||||||
|
|
||||||
dump_logs();
|
collect_logs(false);
|
||||||
|
|
||||||
if (no_secure_dir) {
|
if (no_secure_dir) {
|
||||||
// It's safe to create the folder at this point if the system didn't create it
|
// It's safe to create the folder at this point if the system didn't create it
|
||||||
@ -313,6 +319,8 @@ void boot_complete(int client) {
|
|||||||
write_int(client, 0);
|
write_int(client, 0);
|
||||||
close(client);
|
close(client);
|
||||||
|
|
||||||
|
collect_logs(false);
|
||||||
|
|
||||||
if (!pfs_done || safe_mode)
|
if (!pfs_done || safe_mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user