Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Jul 2010 23:01:10 -0700
From:      Garrett Cooper <yanegomi@gmail.com>
To:        hackers@freebsd.org
Subject:   nanosleep - does it make sense with tv_sec < 0?
Message-ID:  <AANLkTinkwvK2tHZ0okZE48bvW8-N4WBOm284fVK2Xi3F@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTinkwvK2tHZ0okZE48bvW8-N4WBOm284fVK2Xi3F>