diff mbox series

[3/3] libmultipath: tur: protect pthread_cond_timedwait with a loop

Message ID 20240105184037.16518-4-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>

Defect reported by coverity (413383 Data race condition)

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/checkers/tur.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c
index eb2fca1..2800446 100644
--- a/libmultipath/checkers/tur.c
+++ b/libmultipath/checkers/tur.c
@@ -438,9 +438,12 @@  int libcheck_check(struct checker * c)
 		}
 		tur_timeout(&tsp);
 		pthread_mutex_lock(&ct->lock);
-		if (ct->state == PATH_PENDING && ct->msgid == MSG_TUR_RUNNING)
-			r = pthread_cond_timedwait(&ct->active, &ct->lock,
-						   &tsp);
+
+		for (r = 0;
+		     r == 0 && ct->state == PATH_PENDING &&
+			     ct->msgid == MSG_TUR_RUNNING;
+		     r = pthread_cond_timedwait(&ct->active, &ct->lock, &tsp));
+
 		if (!r) {
 			tur_status = ct->state;
 			c->msgid = ct->msgid;