From owner-svn-src-stable-12@freebsd.org Mon Sep 30 06:09:33 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1E9D6FC850; Mon, 30 Sep 2019 06:09:33 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46hX6h6rSyz4Rvh; Mon, 30 Sep 2019 06:09:32 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CF41A26164; Mon, 30 Sep 2019 06:09:32 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x8U69WWt061690; Mon, 30 Sep 2019 06:09:32 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x8U69W9a061688; Mon, 30 Sep 2019 06:09:32 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201909300609.x8U69W9a061688@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Mon, 30 Sep 2019 06:09:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r352889 - stable/12/usr.bin/top X-SVN-Group: stable-12 X-SVN-Commit-Author: dim X-SVN-Commit-Paths: stable/12/usr.bin/top X-SVN-Commit-Revision: 352889 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Sep 2019 06:09:33 -0000 Author: dim Date: Mon Sep 30 06:09:32 2019 New Revision: 352889 URL: https://svnweb.freebsd.org/changeset/base/352889 Log: MFC r352804: Correct the final argument name in the top(1) manpage. The description talks about 'number', while the final argument was 'count'. Since 'count' is already used for the count of displays, change the final argument name to 'number'. MFC r352818: Make fractional delays for top(1) work for interactive mode. In r334906, the -s option was changed to allow fractional times, but this only functioned correctly for batch mode. In interactive mode, any delay below 1.0 would get floored to zero. This would put top(1) into a tight loop, which could be difficult to interrupt. Fix this by storing the -s option value (after validation) into a struct timeval, and using that struct consistently for delaying with select(2). Next up is to allow interactive entry of a fractional delay value. MFC r352819: 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. Modified: stable/12/usr.bin/top/top.1 stable/12/usr.bin/top/top.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.bin/top/top.1 ============================================================================== --- stable/12/usr.bin/top/top.1 Mon Sep 30 06:04:22 2019 (r352888) +++ stable/12/usr.bin/top/top.1 Mon Sep 30 06:09:32 2019 (r352889) @@ -15,7 +15,7 @@ .Op Fl s Ar time .Op Fl o Ar field .Op Fl p Ar pid -.Op Ar count +.Op Ar number .Sh DESCRIPTION .Nm displays the top @@ -144,7 +144,7 @@ no information is available about the percentage of ti .It Fl s Ar time Set the delay between screen updates to .Ar time -seconds. +seconds, which may be fractional. The default delay between updates is 1 second. .It Fl o Ar field Sort the process display area on the specified field. Modified: stable/12/usr.bin/top/top.c ============================================================================== --- stable/12/usr.bin/top/top.c Mon Sep 30 06:04:22 2019 (r352888) +++ stable/12/usr.bin/top/top.c Mon Sep 30 06:09:32 2019 (r352889) @@ -232,7 +232,7 @@ main(int argc, const char *argv[]) static char tempbuf2[50]; sigset_t old_sigmask, new_sigmask; int topn = Infinity; - double delay = 2; + struct timeval delay = { 2, 0 }; int displays = 0; /* indicates unspecified */ int sel_ret = 0; time_t curr_time; @@ -371,21 +371,27 @@ main(int argc, const char *argv[]) break; } - case 's': - delay = strtod(optarg, &nptr); - if (nptr == optarg) { - warnx("warning: invalid delay"); - delay = 2; - warnings++; - } - if (delay < 0) { - warnx("warning: seconds delay should be positive -- using default"); - delay = 2; - warnings++; - } + case 's': + { + double delay_d = strtod(optarg, &nptr); + if (nptr == optarg) + { + warnx("warning: invalid delay"); + warnings++; + } + else if (delay_d <= 0) + { + warnx("warning: seconds delay should be positive -- using default"); + warnings++; + } + else + { + delay.tv_sec = delay_d; + delay.tv_usec = (delay_d - delay.tv_sec) * 1e6; + } + break; + } - break; - case 'q': /* be quick about it */ errno = 0; i = setpriority(PRIO_PROCESS, 0, PRIO_MIN); @@ -698,7 +704,8 @@ restart: no_command = true; if (!interactive) { - usleep(delay * 1e6); + timeout = delay; + select(0, NULL, NULL, NULL, &timeout); if (leaveflag) { end_screen(); exit(0); @@ -712,8 +719,7 @@ restart: /* set up arguments for select with timeout */ FD_ZERO(&readfds); FD_SET(0, &readfds); /* for standard input */ - timeout.tv_sec = delay; - timeout.tv_usec = 0; + timeout = delay; if (leaveflag) { end_screen(); @@ -874,14 +880,22 @@ restart: case CMD_delay: /* new seconds delay */ new_message(MT_standout, "Seconds to delay: "); - if ((i = readline(tempbuf1, 8, true)) > -1) + if ((i = readline(tempbuf1, 8, false)) > 0) { - if ((delay = i) == 0) + double delay_d = strtod(tempbuf1, &nptr); + if (nptr == tempbuf1 || delay_d <= 0) { - delay = 1; + 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 */