[Toybox] [PATCH] toys/sleep: Fix nanosleep() usage.

Georgi Chorbadzhiyski gf at unixsol.org
Thu Mar 8 23:20:23 PST 2012


---
 toys/sleep.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/toys/sleep.c b/toys/sleep.c
index 471011b..ed8523f 100644
--- a/toys/sleep.c
+++ b/toys/sleep.c
@@ -49,7 +49,13 @@ void sleep_main(void)
 		l = (unsigned long)d;
 		d -= l;
 		if (l) toys.exitval = sleep(l);
-		if (!toys.exitval)
-			toys.exitval = nanosleep((unsigned long)(d * 1000000000));
+		if (!toys.exitval) {
+			unsigned long usec = d * 1000000;
+			struct timespec tv = {
+				.tv_sec = usec / 1000000,
+				.tv_nsec = (usec % 1000000) * 1000
+			};
+			toys.exitval = nanosleep(&tv, NULL);
+		}
 	}
 }
-- 
1.7.5.1




More information about the Toybox mailing list