aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-11-29 12:40:25 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-29 12:40:25 +0100
commit6a55b4e403979ba299261816a7ec1bb55bbf3f2b (patch)
treed8eba6a7c1483c33547549b07081e9549baa094c
parentb86a9ed699e2c4693167d6ead00ac307bd9c01c6 (diff)
downloadbusybox-w32-6a55b4e403979ba299261816a7ec1bb55bbf3f2b.tar.gz
busybox-w32-6a55b4e403979ba299261816a7ec1bb55bbf3f2b.tar.bz2
busybox-w32-6a55b4e403979ba299261816a7ec1bb55bbf3f2b.zip
libbb: introduce and use msleep()
function old new delta msleep - 45 +45 watchdog_main 271 266 -5 common_traceroute_main 3546 3530 -16 beep_main 277 248 -29 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 45/-50) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h3
-rw-r--r--libbb/bb_do_delay.c15
-rw-r--r--miscutils/beep.c4
-rw-r--r--miscutils/watchdog.c2
-rw-r--r--networking/traceroute.c2
5 files changed, 20 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 9fa0ce90d..18dc9f935 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1602,7 +1602,8 @@ char *bb_simplify_path(const char *path) FAST_FUNC;
1602char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC; 1602char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
1603 1603
1604void pause_after_failed_login(void) FAST_FUNC; 1604void pause_after_failed_login(void) FAST_FUNC;
1605void bb_do_delay(int seconds) FAST_FUNC; 1605void bb_do_delay(unsigned seconds) FAST_FUNC;
1606void msleep(unsigned ms) FAST_FUNC;
1606void sleep1(void) FAST_FUNC; 1607void sleep1(void) FAST_FUNC;
1607void change_identity(const struct passwd *pw) FAST_FUNC; 1608void change_identity(const struct passwd *pw) FAST_FUNC;
1608void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC; 1609void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
diff --git a/libbb/bb_do_delay.c b/libbb/bb_do_delay.c
index 3a86dc2ae..3dbf032db 100644
--- a/libbb/bb_do_delay.c
+++ b/libbb/bb_do_delay.c
@@ -8,7 +8,7 @@
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10 10
11/* void FAST_FUNC bb_do_delay(int seconds) { ... } - no users yet */ 11/* void FAST_FUNC bb_do_delay(unsigned seconds) { ... } - no users yet */
12 12
13#ifndef LOGIN_FAIL_DELAY 13#ifndef LOGIN_FAIL_DELAY
14#define LOGIN_FAIL_DELAY 3 14#define LOGIN_FAIL_DELAY 3
@@ -34,3 +34,16 @@ void FAST_FUNC sleep1(void)
34 sleep(1); 34 sleep(1);
35} 35}
36 36
37void FAST_FUNC msleep(unsigned ms)
38{
39 /* 1. usleep(n) is not guaranteed by standards to accept n >= 1000000
40 * 2. multiplication in usleep(ms * 1000) can overflow if ms > 4294967
41 * (sleep of ~71.5 minutes)
42 * Let's play safe and loop:
43 */
44 while (ms > 500) {
45 usleep(500000);
46 ms -= 500;
47 }
48 usleep(ms * 1000);
49}
diff --git a/miscutils/beep.c b/miscutils/beep.c
index 1669332fd..7c60aed08 100644
--- a/miscutils/beep.c
+++ b/miscutils/beep.c
@@ -114,10 +114,10 @@ int beep_main(int argc, char **argv)
114 while (rep) { 114 while (rep) {
115//bb_error_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); 115//bb_error_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
116 xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq); 116 xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq);
117 usleep(1000 * length); 117 msleep(length);
118 ioctl(speaker, KIOCSOUND, (void*)0); 118 ioctl(speaker, KIOCSOUND, (void*)0);
119 if (--rep) 119 if (--rep)
120 usleep(1000 * delay); 120 msleep(delay);
121 } 121 }
122 } 122 }
123 123
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index 8c8d7217f..971b777a3 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -143,7 +143,7 @@ int watchdog_main(int argc UNUSED_PARAM, char **argv)
143 * as the counter value is undefined at this point -- PFM 143 * as the counter value is undefined at this point -- PFM
144 */ 144 */
145 write(3, "", 1); /* write zero byte */ 145 write(3, "", 1); /* write zero byte */
146 usleep(stimer_duration * 1000L); 146 msleep(stimer_duration);
147 } 147 }
148 return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */ 148 return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */
149} 149}
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 1c4dc3e4a..34d2a09dd 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -1071,7 +1071,7 @@ common_traceroute_main(int op, char **argv)
1071 1071
1072 fflush_all(); 1072 fflush_all();
1073 if (probe != 0 && pausemsecs > 0) 1073 if (probe != 0 && pausemsecs > 0)
1074 usleep(pausemsecs * 1000); 1074 msleep(pausemsecs);
1075 1075
1076 send_probe(++seq, ttl); 1076 send_probe(++seq, ttl);
1077 t2 = t1 = monotonic_us(); 1077 t2 = t1 = monotonic_us();