summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-03-20 04:49:17 +0000
committercheloha <cheloha@openbsd.org>2020-03-20 04:49:17 +0000
commiteb550d275596aba28d64c251e7258bd13cd17570 (patch)
treed7ddef8aa8df070b44408ed2dabdfd3dfba7161d
parentkevent(2): tsleep(9) -> tsleep_nsec(9) (diff)
downloadwireguard-openbsd-eb550d275596aba28d64c251e7258bd13cd17570.tar.xz
wireguard-openbsd-eb550d275596aba28d64c251e7258bd13cd17570.zip
__thrsleep(2): fix absolute timeout check
An absolute timeout T elapses when the clock has reached time T, i.e. when T is less than or equal to the clock's current time. But the current code thinks T elapses only when the clock is strictly greater than T. For example, if my absolute timeout is 1.00000000, the current code will not return EWOULDBLOCK until the clock reaches 1.00000001. This is wrong: my absolute timeout elapses a nanosecond prior to that point. So the timespeccmp(3) here should be timespeccmp(tsp, &now, <=) and not timespeccmp(tsp, &now, <) as it is currently.
-rw-r--r--sys/kern/kern_synch.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index c2c853df56b..81f6c14c50e 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_synch.c,v 1.164 2020/03/13 16:35:09 claudio Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.165 2020/03/20 04:49:17 cheloha Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
@@ -688,7 +688,7 @@ thrsleep(struct proc *p, struct sys___thrsleep_args *v)
ktrabstimespec(p, tsp);
#endif
- if (timespeccmp(tsp, &now, <)) {
+ if (timespeccmp(tsp, &now, <=)) {
/* already passed: still do the unlock */
if ((error = thrsleep_unlock(lock)))
return (error);