aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-08-03 18:17:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-08-03 18:17:12 +0200
commit4c20d9f2b0223874e2b5ac1235d5f33fdd02589b (patch)
treee533a2de1fe3e146bb1dcd410e7c6ff6b68fa0a6 /procps
parent9b1c8bf89be668a533505e5fb4405bac6eed651c (diff)
downloadbusybox-4c20d9f2b0223874e2b5ac1235d5f33fdd02589b.tar.gz
extend fractional duration support to "top -d N.N" and "timeout"
function old new delta parse_duration_str - 168 +168 sleep_for_duration - 157 +157 top_main 885 928 +43 timeout_main 269 312 +43 handle_input 571 614 +43 duration_suffixes - 40 +40 sfx 40 - -40 sleep_main 364 79 -285 ------------------------------------------------------------------------------ (add/remove: 4/1 grow/shrink: 3/1 up/down: 494/-325) Total: 169 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r--procps/top.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/procps/top.c b/procps/top.c
index 1b49a5e6b..f016f5501 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -901,11 +901,11 @@ enum {
};
#if ENABLE_FEATURE_TOP_INTERACTIVE
-static unsigned handle_input(unsigned scan_mask, unsigned interval)
+static unsigned handle_input(unsigned scan_mask, duration_t interval)
{
if (option_mask32 & OPT_EOF) {
/* EOF on stdin ("top </dev/null") */
- sleep(interval);
+ sleep_for_duration(interval);
return scan_mask;
}
@@ -1092,9 +1092,9 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval)
int top_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int top_main(int argc UNUSED_PARAM, char **argv)
{
+ duration_t interval;
int iterations;
unsigned col;
- unsigned interval;
char *str_interval, *str_iterations;
unsigned scan_mask = TOP_MASK;
@@ -1120,8 +1120,10 @@ int top_main(int argc UNUSED_PARAM, char **argv)
/* work around for "-d 1" -> "-d -1" done by make_all_argv_opts() */
if (str_interval[0] == '-')
str_interval++;
+ interval = parse_duration_str(str_interval);
/* Need to limit it to not overflow poll timeout */
- interval = xatou16(str_interval);
+ if (interval > INT_MAX / 1000)
+ interval = INT_MAX / 1000;
}
if (col & OPT_n) {
if (str_iterations[0] == '-')
@@ -1169,7 +1171,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
/* We output to stdout, we need size of stdout (not stdin)! */
get_terminal_width_height(STDOUT_FILENO, &col, &G.lines);
if (G.lines < 5 || col < 10) {
- sleep(interval);
+ sleep_for_duration(interval);
continue;
}
if (col > LINE_BUF_SIZE - 2)
@@ -1254,7 +1256,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
break;
#if !ENABLE_FEATURE_TOP_INTERACTIVE
clearmems();
- sleep(interval);
+ sleep_for_duration(interval);
#else
new_mask = handle_input(scan_mask, interval);
if (new_mask == NO_RESCAN_MASK)