Commit 421277d7 authored by topjohnwu's avatar topjohnwu

Prevent race conditions in connect_companion

parent 56988944
...@@ -190,10 +190,13 @@ static bool get_exe(int pid, char *buf, size_t sz) { ...@@ -190,10 +190,13 @@ static bool get_exe(int pid, char *buf, size_t sz) {
return xreadlink(buf, buf, sz) > 0; return xreadlink(buf, buf, sz) > 0;
} }
static pthread_mutex_t zygiskd_lock = PTHREAD_MUTEX_INITIALIZER;
static int zygiskd_sockets[] = { -1, -1 }; static int zygiskd_sockets[] = { -1, -1 };
#define zygiskd_socket zygiskd_sockets[is_64_bit] #define zygiskd_socket zygiskd_sockets[is_64_bit]
static void connect_companion(int client, bool is_64_bit) { static void connect_companion(int client, bool is_64_bit) {
mutex_guard g(zygiskd_lock);
if (zygiskd_socket >= 0) { if (zygiskd_socket >= 0) {
// Make sure the socket is still valid // Make sure the socket is still valid
pollfd pfd = { zygiskd_socket, 0, 0 }; pollfd pfd = { zygiskd_socket, 0, 0 };
...@@ -222,6 +225,7 @@ static void connect_companion(int client, bool is_64_bit) { ...@@ -222,6 +225,7 @@ static void connect_companion(int client, bool is_64_bit) {
send_fds(zygiskd_socket, module_fds.data(), module_fds.size()); send_fds(zygiskd_socket, module_fds.data(), module_fds.size());
// Wait for ack // Wait for ack
if (read_int(zygiskd_socket) != 0) { if (read_int(zygiskd_socket) != 0) {
LOGE("zygiskd startup error\n");
return; return;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment