# HG changeset patch # User Thomas Klausner # Date 1561023209 -7200 # Node ID b8afaf63f65ade93d8a53b94c5f2164d1a6492b0 # Parent 2bd83cd4d2b22eeff9e689988ed3d5de78806b52 Handle case where pthread_cond_timedwait returns EINVAL if abstime has passed before it was called. diff -r 2bd83cd4d2b2 -r b8afaf63f65a libfdproto/sessions.c --- a/libfdproto/sessions.c Thu Jun 20 10:37:54 2019 +0200 +++ b/libfdproto/sessions.c Thu Jun 20 11:33:29 2019 +0200 @@ -206,12 +206,27 @@ /* If first session is not expired, we just wait until it happens */ if ( TS_IS_INFERIOR( &now, &first->timeout ) ) { - CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cond, &exp_lock, &first->timeout ), - ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */, - /* on other error, */ break ); + int ret; - /* on wakeup, loop */ - goto again; + ret = pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout); + switch (ret) { + case 0: + case ETIMEDOUT: + /* on wakeup or time-out, loop */ + goto again; + case EINVAL: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) { + break; + } + if (TS_IS_INFERIOR(&now, &first->timeout)) { + TRACE_DEBUG(FULL, "'pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout)' : timer expired before loop could start"); + goto again; + } + /* FALLTHROUGH */ + default: + TRACE_ERROR("ERROR: in 'pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout)' :\t%s", strerror(ret)); + break; + } } /* Now, the first session in the list is expired; destroy it */