From: cheloha Date: Fri, 2 Feb 2018 16:46:37 +0000 (+0000) Subject: Extend range for seconds from 100 million to upper bound of time_t. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fb81ce644970df72956c71d272e173ea820b5f46;p=openbsd Extend range for seconds from 100 million to upper bound of time_t. 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@ --- diff --git a/bin/sleep/sleep.c b/bin/sleep/sleep.c index d25ad44749f..cbd54767ee7 100644 --- a/bin/sleep/sleep.c +++ b/bin/sleep/sleep.c @@ -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); }