summaryrefslogtreecommitdiff
path: root/sys/kern/kern_time.c
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-17 06:11:06 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-17 06:11:06 +0000
commit567cb80ef9c33bb9ce4ee2e8d7c5101fd50d3538 (patch)
tree9c87428afdcea22fa994819f9897513ee55c18a0 /sys/kern/kern_time.c
parent92d167eefc85ab1a4d2050e37dbc5a6b3723ee42 (diff)
Repeat. But this time get the math right and avoid sleeping forever.
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r--sys/kern/kern_time.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index a67a5780efe..a8444eac2ea 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.27 2002/02/15 18:51:20 pvalchev Exp $ */
+/* $OpenBSD: kern_time.c,v 1.28 2002/02/17 06:11:05 art Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -189,13 +189,13 @@ sys_nanosleep(p, v, retval)
register_t *retval;
{
static int nanowait;
- register struct sys_nanosleep_args/* {
+ struct sys_nanosleep_args/* {
syscallarg(const struct timespec *) rqtp;
syscallarg(struct timespec *) rmtp;
} */ *uap = v;
struct timespec rqt;
struct timespec rmt;
- struct timeval atv, utv;
+ struct timeval stv, etv, atv;
int error, s, timo;
error = copyin((const void *)SCARG(uap, rqtp), (void *)&rqt,
@@ -207,13 +207,15 @@ sys_nanosleep(p, v, retval)
if (itimerfix(&atv))
return (EINVAL);
- s = splclock();
- timeradd(&atv,&time,&atv);
- timo = hzto(&atv);
- splx(s);
- /*
- * Avoid inadvertantly sleeping forever
- */
+ if (SCARG(uap, rmtp)) {
+ s = splclock();
+ stv = mono_time;
+ splx(s);
+ }
+
+ timo = tvtohz(&atv);
+
+ /* Avoid sleeping forever. */
if (timo <= 0)
timo = 1;
@@ -227,14 +229,16 @@ sys_nanosleep(p, v, retval)
int error;
s = splclock();
- utv = time;
+ etv = mono_time;
splx(s);
- timersub(&atv, &utv, &utv);
- if (utv.tv_sec < 0)
- timerclear(&utv);
+ timersub(&etv, &stv, &stv);
+ timersub(&atv, &stv, &atv);
+
+ if (atv.tv_sec < 0)
+ timerclear(&atv);
- TIMEVAL_TO_TIMESPEC(&utv, &rmt);
+ TIMEVAL_TO_TIMESPEC(&atv, &rmt);
error = copyout((void *)&rmt, (void *)SCARG(uap,rmtp),
sizeof(rmt));
if (error)