diff mbox series

[1/3] multipathd: init_unwinder: protect pthread_cond_wait() call with a loop

Message ID 20240105184037.16518-2-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools: coverity defect fixes | expand

Commit Message

Martin Wilck Jan. 5, 2024, 6:40 p.m. UTC
From: Martin Wilck <mwilck@suse.com>

This fixes a coverity-reported defect (413387 Indefinite wait).

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 multipathd/init_unwinder.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/multipathd/init_unwinder.c b/multipathd/init_unwinder.c
index 14467f3..b1cd283 100644
--- a/multipathd/init_unwinder.c
+++ b/multipathd/init_unwinder.c
@@ -4,10 +4,12 @@ 
 
 static pthread_mutex_t dummy_mtx = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER;
+static int dummy_started;
 
 static void *dummy_thread(void *arg __attribute__((unused)))
 {
 	pthread_mutex_lock(&dummy_mtx);
+	dummy_started = 1;
 	pthread_cond_broadcast(&dummy_cond);
 	pthread_mutex_unlock(&dummy_mtx);
 	pause();
@@ -27,7 +29,9 @@  int init_unwinder(void)
 		return rc;
 	}
 
-	pthread_cond_wait(&dummy_cond, &dummy_mtx);
+	while (!dummy_started)
+		pthread_cond_wait(&dummy_cond, &dummy_mtx);
+
 	pthread_mutex_unlock(&dummy_mtx);
 
 	return pthread_cancel(dummy);