Run pthread_atfork only once

Close #7704
This commit is contained in:
topjohnwu 2024-01-25 00:17:05 -08:00
parent b44141ae39
commit f2c4288d2d
4 changed files with 8 additions and 2 deletions

View File

@ -433,6 +433,7 @@ static void daemon_entry() {
register_poll(&main_socket_pfd, handle_request); register_poll(&main_socket_pfd, handle_request);
// Loop forever to listen for requests // Loop forever to listen for requests
init_thread_pool();
poll_loop(); poll_loop();
} }

View File

@ -52,6 +52,7 @@ void unregister_poll(int fd, bool auto_close);
void clear_poll(); void clear_poll();
// Thread pool // Thread pool
void init_thread_pool();
void exec_task(std::function<void()> &&task); void exec_task(std::function<void()> &&task);
// Daemon handlers // Daemon handlers

View File

@ -42,8 +42,6 @@ static void reset_pool() {
} }
static void *thread_pool_loop(void * const is_core_pool) { static void *thread_pool_loop(void * const is_core_pool) {
pthread_atfork(nullptr, nullptr, &reset_pool);
// Block all signals // Block all signals
sigset_t mask; sigset_t mask;
sigfillset(&mask); sigfillset(&mask);
@ -83,6 +81,10 @@ static void *thread_pool_loop(void * const is_core_pool) {
} }
} }
void init_thread_pool() {
pthread_atfork(nullptr, nullptr, &reset_pool);
}
void exec_task(function<void()> &&task) { void exec_task(function<void()> &&task) {
mutex_guard g(lock); mutex_guard g(lock);
pending_task.swap(task); pending_task.swap(task);

View File

@ -15,6 +15,8 @@ static void zygiskd(int socket) {
if (getuid() != 0 || fcntl(socket, F_GETFD) < 0) if (getuid() != 0 || fcntl(socket, F_GETFD) < 0)
exit(-1); exit(-1);
init_thread_pool();
#if defined(__LP64__) #if defined(__LP64__)
set_nice_name("zygiskd64"); set_nice_name("zygiskd64");
LOGI("* Launching zygiskd64\n"); LOGI("* Launching zygiskd64\n");