From 4c20d9f2b0223874e2b5ac1235d5f33fdd02589b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 3 Aug 2018 18:17:12 +0200 Subject: 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 --- procps/top.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'procps') 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 "-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) -- cgit v1.2.3