git » libfilo » commit 3343ca2

Allow sem_wait() to fail, as specified by POSIX.

author Alberto Bertogli
2005-04-23 23:35:56 UTC
committer Alberto Bertogli
2005-04-23 23:35:56 UTC
parent a6bd4eb6812cf609675125f3210fc81454ce1a6c

Allow sem_wait() to fail, as specified by POSIX.
sem_wait() can fail with EINTR, which is easily triggable by stracing the
process. The problem is that as of today, Linux manfiles don't list EINTR as a
possible error for sem_wait(), so it was a bit tricky to find. I should have
learned not to trust manpages by now. Anyway, this is the fix.

libfilo.c +3 -1

diff --git a/libfilo.c b/libfilo.c
index e9c30cd..f1d9347 100644
--- a/libfilo.c
+++ b/libfilo.c
@@ -355,7 +355,9 @@ static void wait_on(filock_t *fl, off_t start, off_t end, int mode)
 	fl_unlock(fl);
 
 	/* block until some other thread wakes us up */
-	sem_wait(&(wr->sem));
+	while (sem_wait(&(wr->sem)) != 0)
+		/* it can fail with EINTR, retry */
+		;
 
 	free(wr);
 }