sleep(1): support longer naps (redux)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

sleep(1): support longer naps (redux)

Scott Cheloha
Now that we have removed the 100 million second upper bound we can
remove this awful loop.

Effectively a revert of sleep.c 1.25.

ok?

Index: sleep.c
===================================================================
RCS file: /cvs/src/bin/sleep/sleep.c,v
retrieving revision 1.26
diff -u -p -r1.26 sleep.c
--- sleep.c 4 Feb 2018 02:18:15 -0000 1.26
+++ sleep.c 10 Jan 2019 15:45:23 -0000
@@ -30,6 +30,8 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/time.h>
+
 #include <ctype.h>
 #include <signal.h>
 #include <stdio.h>
@@ -101,24 +103,14 @@ main(int argc, char *argv[])
  }
  }
 
- 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))
+ rqtp.tv_sec = secs;
+ rqtp.tv_nsec = nsecs;
+
+ if (timespecisset(&rqtp)) {
+ if (nanosleep(&rqtp, NULL) == -1)
  err(1, NULL);
- secs -= rqtp.tv_sec;
- nsecs -= rqtp.tv_nsec;
  }
+
  return (0);
 }
 

Reply | Threaded
Open this post in threaded view
|

Re: sleep(1): support longer naps (redux)

Jeremie Courreges-Anglas-5
On Thu, Jan 10 2019, Scott Cheloha <[hidden email]> wrote:
> Now that we have removed the 100 million second upper bound we can
> remove this awful loop.
>
> Effectively a revert of sleep.c 1.25.
>
> ok?

ok

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE