From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 2 08:09:30 2010 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7DEBF106564A for ; Mon, 2 Aug 2010 08:09:30 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 446CD8FC0C for ; Mon, 2 Aug 2010 08:09:30 +0000 (UTC) Received: by iwn35 with SMTP id 35so5124857iwn.13 for ; Mon, 02 Aug 2010 01:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=dB0R4UQDKDwjUqfxVPrSeKNgFfnQDfNC/Np8npthjrk=; b=Hv3E3d+vYdMGmCYIGrfCmLuQ9bLf1uyFWLo3pZpbMhz3sJRd+ooh94BNJwfuaiLoJC obUsusyVY+/AAHI6uDCK6phBocpeOQIxNYpIkzfeMkpjiuxeC+Xm5w0Sx2VrbqEUjROx 7AwzvEB0EXy6SqpvqStR12DTez37FUF2ALeh8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=X1fVnYb3QgU61vhcjAf0QVVVjkCwNTIHrzjHH+huHRmO8nFsNjbXI0FjkJM2NJZV0j wr3z4dFzi4CbV6bq1PXHMmdYX2NhnnjVrTd7O8rARGIRFOdwdrqHOn8+IcFa+hNreSBd 6cdQV26Oixxy2z0xt+Dxl3eQ1K57Aht7nayxo= MIME-Version: 1.0 Received: by 10.231.174.65 with SMTP id s1mr6723403ibz.3.1280736569609; Mon, 02 Aug 2010 01:09:29 -0700 (PDT) Received: by 10.231.187.104 with HTTP; Mon, 2 Aug 2010 01:09:29 -0700 (PDT) In-Reply-To: References: Date: Mon, 2 Aug 2010 01:09:29 -0700 Message-ID: From: Garrett Cooper To: hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Mon, 02 Aug 2010 11:16:45 +0000 Cc: Subject: Re: nanosleep - does it make sense with tv_sec < 0? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2010 08:09:30 -0000 On Wed, Jul 28, 2010 at 11:01 PM, Garrett Cooper wrote= : > Hi Hackers, > =A0 =A0I ran into an oddity with the POSIX spec that seems a bit unrealis= tic: > > [EINVAL] > =A0 =A0The rqtp argument specified a nanosecond value less than zero or > greater than or equal to 1000 million. > > =A0 =A0Seems 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) > { > =A0 =A0 =A0 =A0struct timespec ts, ts2, ts3; > =A0 =A0 =A0 =A0struct timeval tv; > =A0 =A0 =A0 =A0int error; > > =A0 =A0 =A0 =A0if (rqt->tv_nsec < 0 || rqt->tv_nsec >=3D 1000000000) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (EINVAL); > =A0 =A0 =A0 =A0if (rqt->tv_sec < 0 || (rqt->tv_sec =3D=3D 0 && rqt->tv_ns= ec =3D=3D > 0)) // <-- first clause here > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (0); > > =A0 =A0but I'm wondering whether or not it makes logical sense for us to > do this (sleep for a negative amount of time?)... > =A0 =A0FWIW Linux returns -1 and sets EINVAL in this case, which makes > more sense to me. After talking with the Austin Group folks, this appears to be an [optional] implementation detail with the fact that our time_t is signed. I think that this patch is valid for catching this case, because sleeping negative time doesn't seem logical... Thanks, -Garrett Index: lib/libc/sys/nanosleep.2 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- lib/libc/sys/nanosleep.2 (revision 210226) +++ lib/libc/sys/nanosleep.2 (working copy) @@ -87,19 +87,20 @@ .It Bq Er EINTR The .Fn nanosleep -system call -was interrupted by the delivery of a signal. +system call was interrupted by the delivery of a signal. .It Bq Er EINVAL The .Fa rqtp -argument -specified a nanosecond value less than zero +argument specified a nanosecond value less than zero or greater than or equal to 1000 million. +.It Bq Er EINVAL +The +.Fa rqtp +argument specified a second value less than zero. .It Bq Er ENOSYS The .Fn nanosleep -system call -is not supported by this implementation. +system call is not supported by this implementation. .El .Sh SEE ALSO .Xr sigsuspend 2 , Index: sys/kern/kern_time.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sys/kern/kern_time.c (revision 210226) +++ sys/kern/kern_time.c (working copy) @@ -358,7 +358,9 @@ if (rqt->tv_nsec < 0 || rqt->tv_nsec >=3D 1000000000) return (EINVAL); - if (rqt->tv_sec < 0 || (rqt->tv_sec =3D=3D 0 && rqt->tv_nsec =3D=3D 0)) + if (rqt->tv_sec < 0) + return (EINVAL); + if (rqt->tv_sec =3D=3D 0 && rqt->tv_nsec =3D=3D 0) return (0); getnanouptime(&ts); timespecadd(&ts, rqt);