Refactor magiskrc

This commit is contained in:
LoveSy
2023-03-16 10:26:27 +08:00
committed by John Wu
parent 87e036a190
commit dba5020e4f
9 changed files with 36 additions and 58 deletions

View File

@@ -412,7 +412,7 @@ static void boot_complete() {
get_manager(0, nullptr, true);
}
void boot_stage_handler(int code) {
void boot_stage_handler(int client, int code) {
// Make sure boot stage execution is always serialized
static pthread_mutex_t stage_lock = PTHREAD_MUTEX_INITIALIZER;
mutex_guard lock(stage_lock);
@@ -421,13 +421,15 @@ void boot_stage_handler(int code) {
case MainRequest::POST_FS_DATA:
if ((boot_state & FLAG_POST_FS_DATA_DONE) == 0)
post_fs_data();
close(xopen(UNBLOCKFILE, O_RDONLY | O_CREAT, 0));
close(client);
break;
case MainRequest::LATE_START:
close(client);
if ((boot_state & FLAG_POST_FS_DATA_DONE) && (boot_state & FLAG_SAFE_MODE) == 0)
late_start();
break;
case MainRequest::BOOT_COMPLETE:
close(client);
if ((boot_state & FLAG_SAFE_MODE) == 0)
boot_complete();
break;

View File

@@ -274,8 +274,7 @@ static void handle_request(pollfd *pfd) {
} else if (code < MainRequest::_STAGE_BARRIER_) {
exec_task([=] { handle_request_async(client, code, cred); });
} else {
close(client);
exec_task([=] { boot_stage_handler(code); });
exec_task([=] { boot_stage_handler(client, code); });
}
return;

View File

@@ -90,7 +90,9 @@ int magisk_main(int argc, char *argv[]) {
int fd = connect_daemon(MainRequest::STOP_DAEMON);
return read_int(fd);
} else if (argv[1] == "--post-fs-data"sv) {
close(connect_daemon(MainRequest::POST_FS_DATA, true));
int fd = connect_daemon(MainRequest::POST_FS_DATA, true);
struct pollfd pfd = { fd, POLLIN, 0 };
poll(&pfd, 1, 1000 * POST_FS_DATA_WAIT_TIME);
return 0;
} else if (argv[1] == "--service"sv) {
close(connect_daemon(MainRequest::LATE_START, true));