From fc4ac32fa7b7c4af4a360612cad271afd6dc8cb8 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 27 Sep 2019 20:53:31 +0000 Subject: [PATCH] Allow entering fractional delays in top(1) interactive mode. This uses the same logic as with the -s option, first validating the entered value, then storing the result in a struct timeval. MFC after: 3 days X-MFC-With: r352818 --- usr.bin/top/top.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index cd357a092e9f..3b317fab88b7 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -886,12 +886,22 @@ main(int argc, const char *argv[]) case CMD_delay: /* new seconds delay */ new_message(MT_standout, "Seconds to delay: "); - if ((i = readline(tempbuf1, 8, true)) > 0) + if ((i = readline(tempbuf1, 8, false)) > 0) { - delay.tv_sec = i; - delay.tv_usec = 0; + double delay_d = strtod(tempbuf1, &nptr); + if (nptr == tempbuf1 || delay_d <= 0) + { + new_message(MT_standout, " Invalid delay"); + putchar('\r'); + no_command = true; + } + else + { + delay.tv_sec = delay_d; + delay.tv_usec = (delay_d - delay.tv_sec) * 1e6; + clear_message(); + } } - clear_message(); break; case CMD_displays: /* change display count */