From 93c12a9281c5e39f88ad8f1de7c216d3972f52e6 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 21 Feb 2014 17:49:53 +0100 Subject: [PATCH] android/hal-ipc: Fix race condition when closing IPC Protect command socket cleanup with mutex to avoid bogus exit when stopping notification thread. --- android/hal-ipc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/hal-ipc.c b/android/hal-ipc.c index 99ba38e12..1ba03f5c6 100644 --- a/android/hal-ipc.c +++ b/android/hal-ipc.c @@ -159,8 +159,12 @@ static void *notification_handler(void *data) /* socket was shutdown */ if (ret == 0) { - if (cmd_sk == -1) + pthread_mutex_lock(&cmd_sk_mutex); + if (cmd_sk == -1) { + pthread_mutex_unlock(&cmd_sk_mutex); break; + } + pthread_mutex_unlock(&cmd_sk_mutex); error("Notification socket closed, aborting"); exit(EXIT_FAILURE); @@ -299,8 +303,10 @@ bool hal_ipc_init(void) void hal_ipc_cleanup(void) { + pthread_mutex_lock(&cmd_sk_mutex); close(cmd_sk); cmd_sk = -1; + pthread_mutex_unlock(&cmd_sk_mutex); shutdown(notif_sk, SHUT_RD); -- 2.47.3