Extend range for seconds from 100 million to upper bound of time_t.
authorcheloha <cheloha@openbsd.org>
Fri, 2 Feb 2018 16:46:37 +0000 (16:46 +0000)
committercheloha <cheloha@openbsd.org>
Fri, 2 Feb 2018 16:46:37 +0000 (16:46 +0000)
Makes us compliant with POSIX.1-2008, which requires that sleep(1) support
up to 2147483647 seconds.

Bounced off of tb@ and jca@.

ok tb@ millert@ jca@

bin/sleep/sleep.c

index d25ad44..cbd5476 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sleep.c,v 1.24 2015/10/11 20:17:49 guenther Exp $     */
+/*     $OpenBSD: sleep.c,v 1.25 2018/02/02 16:46:37 cheloha Exp $      */
 /*     $NetBSD: sleep.c,v 1.8 1995/03/21 09:11:11 cgd Exp $    */
 
 /*
@@ -102,12 +102,24 @@ main(int argc, char *argv[])
                }
        }
 
-       rqtp.tv_sec = secs;
-       rqtp.tv_nsec = nsecs;
-
-       if ((secs > 0) || (nsecs > 0))
+       while (secs > 0 || nsecs > 0) {
+               /*
+                * nanosleep(2) supports a maximum of 100 million
+                * seconds, so we break the nap up into multiple
+                * calls if we have more than that.
+                */
+               if (secs > 100000000) {
+                       rqtp.tv_sec = 100000000;
+                       rqtp.tv_nsec = 0;
+               } else {
+                       rqtp.tv_sec = secs;
+                       rqtp.tv_nsec = nsecs;
+               }
                if (nanosleep(&rqtp, NULL))
                        err(1, NULL);
+               secs -= rqtp.tv_sec;
+               nsecs -= rqtp.tv_nsec;
+       }
        return (0);
 }