From 5170eaebb2e0e616e9e8238b167c35a9d0529949 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jan 2024 19:11:00 +0100 Subject: [PATCH] libmultipath: tur: protect pthread_cond_timedwait with a loop Defect reported by coverity (413383 Data race condition) Signed-off-by: Martin Wilck --- libmultipath/checkers/tur.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index eb2fca18c..2800446d6 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;