nanosleep - does it make sense with tv_sec < 0?
Garrett Cooper
yanegomi at gmail.com
Thu Jul 29 06:01:11 UTC 2010
Hi Hackers,
I ran into an oddity with the POSIX spec that seems a bit unrealistic:
[EINVAL]
The rqtp argument specified a nanosecond value less than zero or
greater than or equal to 1000 million.
Seems like it should also apply for seconds < 0. We current
silently pass this argument in kern/kern_time.c:kern_nanosleep:
int
kern_nanosleep(struct thread *td, struct timespec *rqt, struct timespec *rmt)
{
struct timespec ts, ts2, ts3;
struct timeval tv;
int error;
if (rqt->tv_nsec < 0 || rqt->tv_nsec >= 1000000000)
return (EINVAL);
if (rqt->tv_sec < 0 || (rqt->tv_sec == 0 && rqt->tv_nsec ==
0)) // <-- first clause here
return (0);
but I'm wondering whether or not it makes logical sense for us to
do this (sleep for a negative amount of time?)...
FWIW Linux returns -1 and sets EINVAL in this case, which makes
more sense to me.
Thanks,
-Garrett
More information about the freebsd-hackers
mailing list