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-w32-4c20d9f2b0223874e2b5ac1235d5f33fdd02589b.tar.gz
busybox-w32-4c20d9f2b0223874e2b5ac1235d5f33fdd02589b.tar.bz2
busybox-w32-4c20d9f2b0223874e2b5ac1235d5f33fdd02589b.zip
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 {
901}; 901};
902 902
903#if ENABLE_FEATURE_TOP_INTERACTIVE 903#if ENABLE_FEATURE_TOP_INTERACTIVE
904static unsigned handle_input(unsigned scan_mask, unsigned interval) 904static unsigned handle_input(unsigned scan_mask, duration_t interval)
905{ 905{
906 if (option_mask32 & OPT_EOF) { 906 if (option_mask32 & OPT_EOF) {
907 /* EOF on stdin ("top </dev/null") */ 907 /* EOF on stdin ("top </dev/null") */
908 sleep(interval); 908 sleep_for_duration(interval);
909 return scan_mask; 909 return scan_mask;
910 } 910 }
911 911
@@ -1092,9 +1092,9 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval)
1092int top_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1092int top_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1093int top_main(int argc UNUSED_PARAM, char **argv) 1093int top_main(int argc UNUSED_PARAM, char **argv)
1094{ 1094{
1095 duration_t interval;
1095 int iterations; 1096 int iterations;
1096 unsigned col; 1097 unsigned col;
1097 unsigned interval;
1098 char *str_interval, *str_iterations; 1098 char *str_interval, *str_iterations;
1099 unsigned scan_mask = TOP_MASK; 1099 unsigned scan_mask = TOP_MASK;
1100 1100
@@ -1120,8 +1120,10 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1120 /* work around for "-d 1" -> "-d -1" done by make_all_argv_opts() */ 1120 /* work around for "-d 1" -> "-d -1" done by make_all_argv_opts() */
1121 if (str_interval[0] == '-') 1121 if (str_interval[0] == '-')
1122 str_interval++; 1122 str_interval++;
1123 interval = parse_duration_str(str_interval);
1123 /* Need to limit it to not overflow poll timeout */ 1124 /* Need to limit it to not overflow poll timeout */
1124 interval = xatou16(str_interval); 1125 if (interval > INT_MAX / 1000)
1126 interval = INT_MAX / 1000;
1125 } 1127 }
1126 if (col & OPT_n) { 1128 if (col & OPT_n) {
1127 if (str_iterations[0] == '-') 1129 if (str_iterations[0] == '-')
@@ -1169,7 +1171,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1169 /* We output to stdout, we need size of stdout (not stdin)! */ 1171 /* We output to stdout, we need size of stdout (not stdin)! */
1170 get_terminal_width_height(STDOUT_FILENO, &col, &G.lines); 1172 get_terminal_width_height(STDOUT_FILENO, &col, &G.lines);
1171 if (G.lines < 5 || col < 10) { 1173 if (G.lines < 5 || col < 10) {
1172 sleep(interval); 1174 sleep_for_duration(interval);
1173 continue; 1175 continue;
1174 } 1176 }
1175 if (col > LINE_BUF_SIZE - 2) 1177 if (col > LINE_BUF_SIZE - 2)
@@ -1254,7 +1256,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1254 break; 1256 break;
1255#if !ENABLE_FEATURE_TOP_INTERACTIVE 1257#if !ENABLE_FEATURE_TOP_INTERACTIVE
1256 clearmems(); 1258 clearmems();
1257 sleep(interval); 1259 sleep_for_duration(interval);
1258#else 1260#else
1259 new_mask = handle_input(scan_mask, interval); 1261 new_mask = handle_input(scan_mask, interval);
1260 if (new_mask == NO_RESCAN_MASK) 1262 if (new_mask == NO_RESCAN_MASK)