Fix the code that deals with very long sleeps (> 248 days) which
go beyond the maximum that the callout mechanism can handle. [See the comments in tvtohz() in subr_sleep.c for the details.] When that happens the timeout is clamped to MAX_INT (ticks), and the code in nanosleep1() looped (or tried to) repeating the sleep (aka kpause()) until the requested end time for the sleep was reached. Unfortunately, the code assumed that kpause() would return 0 when it returned after the timeout expired. But it doesn't, it returns EWOULDBLOCK instead (why is incomprehensible to me, but I assume there is a reason.) [That comes from sleepq_block() which returns EWOULDBLOCK when callout_halt() indicates that the callout had fired, which is exactly what has happened when the time has elapsed.] There was already code to deal with that EWOULDBLOCK and return 0 instead of an error in that case - but it was placed after the error code was tested against 0 for the purposes of the loop. Simply move the EWOULDBLOCK->0 mapping earlier, so the code which is expecting "error == 0" to mean "nothing went wrong" actually gets to see that happen, and the loop can actually loop. (Someday the loop should probably be rewritten as a loop, instead of as a bunch of code followed by a "goto again"!)
This commit is contained in:
parent
58f8d333d6
commit
3f1f0cc730
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kern_time.c,v 1.196 2019/02/24 07:23:11 mlelstv Exp $ */
|
||||
/* $NetBSD: kern_time.c,v 1.197 2019/03/10 14:45:53 kre Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc.
|
||||
@ -61,7 +61,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.196 2019/02/24 07:23:11 mlelstv Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.197 2019/03/10 14:45:53 kre Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/resourcevar.h>
|
||||
@ -350,6 +350,8 @@ nanosleep1(struct lwp *l, clockid_t clock_id, int flags, struct timespec *rqt,
|
||||
timo = 1;
|
||||
again:
|
||||
error = kpause("nanoslp", true, timo, NULL);
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
if (rmt != NULL || error == 0) {
|
||||
struct timespec rmtend;
|
||||
struct timespec t0;
|
||||
@ -374,8 +376,6 @@ again:
|
||||
|
||||
if (error == ERESTART)
|
||||
error = EINTR;
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user