Skip to content

Commit

Permalink
sync: Avoid ridiculously long timeouts
Browse files Browse the repository at this point in the history
On OpenBSD, passing a timeout longer than 100000000 seconds to select(2) will
make it fail with EINVAL.  As this is original 4.4BSD behaviour it is not
inconceivable that other systems suffer from the same problem.  And Linux,
though not suffering from any 4.4BSD heritage, briefly did something similar:

<https://lkml.org/lkml/2012/8/31/263>

So avoid calling AdjustWaitForDelay() instead of setting the timeout to
(effectively) ULONG_MAX milliseconds.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
(cherry picked from commit ddeca92)
  • Loading branch information
kettenis authored and whot committed Mar 12, 2014
1 parent b332cd2 commit b3656c0
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Xext/sync.c
Expand Up @@ -2731,27 +2731,24 @@ IdleTimeBlockHandler(pointer pCounter, struct timeval **wt, pointer LastSelectMa
* If we've been idle more than it, and someone wants to know about
* that level-triggered, schedule an immediate wakeup.
*/
unsigned long timeout = -1;

if (XSyncValueLessThan(idle, *greater)) {
XSyncValue value;
Bool overflow;

XSyncValueSubtract(&value, *greater, idle, &overflow);
timeout = min(timeout, XSyncValueLow32(value));
AdjustWaitForDelay(wt, XSyncValueLow32(value));
}
else {
for (list = counter->sync.pTriglist; list;
list = list->next) {
trig = list->pTrigger;
if (trig->CheckTrigger(trig, old_idle)) {
timeout = min(timeout, 0);
AdjustWaitForDelay(wt, 0);
break;
}
}
}

AdjustWaitForDelay(wt, timeout);
}

counter->value = old_idle; /* pop */
Expand Down

0 comments on commit b3656c0

Please sign in to comment.