diff options
author | bde <bde@FreeBSD.org> | 1997-08-26 00:40:04 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1997-08-26 00:40:04 +0000 |
commit | c86802a2aefedc8e4193d369616e502bb635d002 (patch) | |
tree | 1b85a322779794dbb99d04d934970e777848afdc /sys/kern/kern_time.c | |
parent | 015fbf2e02ae69e8765b8a0d265a4a7eb775f849 (diff) | |
download | FreeBSD-src-c86802a2aefedc8e4193d369616e502bb635d002.zip FreeBSD-src-c86802a2aefedc8e4193d369616e502bb635d002.tar.gz |
Don't return EINVAL for negative timespecs in the nanosleep functions.
Negative timespecs are perfectly valid. Just return 0 immediately
for them. Also, return 0 immediately for zero timespecs.
Fixed some style bugs.
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r-- | sys/kern/kern_time.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index fbb6453..f84e9bb 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_time.c 8.1 (Berkeley) 6/10/93 - * $Id: kern_time.c,v 1.31 1997/08/13 17:55:11 ache Exp $ + * $Id: kern_time.c,v 1.32 1997/08/14 08:15:12 ache Exp $ */ #include <sys/param.h> @@ -61,10 +61,10 @@ struct timezone tz; * timers when they expire. */ -static int settime __P((struct timeval *)); -static void timevalfix __P((struct timeval *)); static int nanosleep1 __P((struct proc *p, struct timespec *rqt, struct timespec *rmt)); +static int settime __P((struct timeval *)); +static void timevalfix __P((struct timeval *)); static int settime(tv) @@ -213,8 +213,10 @@ nanosleep1(p, rqt, rmt) struct timeval atv, utv, rtv; int error, s, timo, i, n; - if (rqt->tv_sec < 0 || rqt->tv_nsec < 0 || rqt->tv_nsec >= 1000000000) + if (rqt->tv_nsec < 0 || rqt->tv_nsec >= 1000000000) return (EINVAL); + if (rqt->tv_sec < 0 || rqt->tv_sec == 0 && rqt->tv_nsec == 0) + return (0); TIMESPEC_TO_TIMEVAL(&atv, rqt) if (itimerfix(&atv)) { @@ -225,9 +227,7 @@ nanosleep1(p, rqt, rmt) } else n = 0; - for (i = 0, error = EWOULDBLOCK; - i <= n && error == EWOULDBLOCK; - i++) { + for (i = 0, error = EWOULDBLOCK; i <= n && error == EWOULDBLOCK; i++) { if (n > 0) { if (i == n) atv = rtv; @@ -248,7 +248,6 @@ nanosleep1(p, rqt, rmt) p->p_sleepend = &atv; error = tsleep(&nanowait, PWAIT | PCATCH, "nanslp", timo); p->p_sleepend = NULL; - if (error == ERESTART) error = EINTR; if (rmt != NULL && (i == n || error != EWOULDBLOCK)) { @@ -306,9 +305,7 @@ nanosleep(p, uap, retval) if (SCARG(uap, rmtp)) if (!useracc((caddr_t)SCARG(uap, rmtp), sizeof(rmt), B_WRITE)) return (EFAULT); - error = nanosleep1(p, &rqt, &rmt); - if (SCARG(uap, rmtp)) { error2 = copyout(&rmt, SCARG(uap, rmtp), sizeof(rmt)); if (error2) /* XXX shouldn't happen, did useracc() above */ @@ -347,13 +344,14 @@ signanosleep(p, uap, retval) if (error) return (error); - /* See kern_sig.c:sigsuspend() for explanation */ + /* See kern_sig.c:sigsuspend() for explanation. */ ps->ps_oldmask = p->p_sigmask; ps->ps_flags |= SAS_OLDMASK; p->p_sigmask = mask &~ sigcantmask; error = nanosleep1(p, &rqt, &rmt); + /* See kern_sig.c:sigsuspend() again. */ p->p_sigmask = ps->ps_oldmask; /* in case timeout rather than sig */ ps->ps_flags &= ~SAS_OLDMASK; @@ -363,7 +361,6 @@ signanosleep(p, uap, retval) return (error2); } return (error); - } #ifndef _SYS_SYSPROTO_H_ |