From owner-svn-src-head@freebsd.org Sun Jun 10 00:02:57 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 91FD41006269; Sun, 10 Jun 2018 00:02:57 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 42D158039A; Sun, 10 Jun 2018 00:02:57 +0000 (UTC) (envelope-from eadler@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 23D4724F82; Sun, 10 Jun 2018 00:02:57 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5A02vmX012216; Sun, 10 Jun 2018 00:02:57 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5A02uBP012215; Sun, 10 Jun 2018 00:02:56 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806100002.w5A02uBP012215@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Sun, 10 Jun 2018 00:02:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334906 - head/usr.bin/top X-SVN-Group: head X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: head/usr.bin/top X-SVN-Commit-Revision: 334906 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jun 2018 00:02:57 -0000 Author: eadler Date: Sun Jun 10 00:02:56 2018 New Revision: 334906 URL: https://svnweb.freebsd.org/changeset/base/334906 Log: top(1): permit sub-second delay times This removes the getuid check for delay==0. It didn't prevent users from writing similar programs in the general case. In theory, if top(1) is among one of the few restricted programs you're allowed to run, it may have helped a little, but there are better ways of handling that case. Modified: head/usr.bin/top/top.c head/usr.bin/top/top.h Modified: head/usr.bin/top/top.c ============================================================================== --- head/usr.bin/top/top.c Sat Jun 9 23:45:05 2018 (r334905) +++ head/usr.bin/top/top.c Sun Jun 10 00:02:56 2018 (r334906) @@ -235,7 +235,7 @@ main(int argc, char *argv[]) static char tempbuf2[50]; int old_sigmask; /* only used for BSD-style signals */ int topn = Infinity; - int delay = Default_DELAY; + double delay = 2; int displays = 0; /* indicates unspecified */ int sel_ret = 0; time_t curr_time; @@ -426,15 +426,16 @@ _Static_assert(sizeof(command_chars) == CMD_toggletid break; } - case 's': - if ((delay = atoi(optarg)) < 0 || (delay == 0 && getuid() != 0)) - { - fprintf(stderr, - "%s: warning: seconds delay should be positive -- using default\n", - myname); - delay = Default_DELAY; - warnings++; - } + case 's': + delay = strtod(optarg, NULL); + if (delay < 0) { + fprintf(stderr, + "%s: warning: seconds delay should be positive -- using default\n", + myname); + delay = 2; + warnings++; + } + break; case 'q': /* be quick about it */ @@ -781,7 +782,7 @@ restart: no_command = true; if (!interactive) { - sleep(delay); + usleep(delay * 1e6); if (leaveflag) { end_screen(); exit(0); Modified: head/usr.bin/top/top.h ============================================================================== --- head/usr.bin/top/top.h Sat Jun 9 23:45:05 2018 (r334905) +++ head/usr.bin/top/top.h Sun Jun 10 00:02:56 2018 (r334906) @@ -1,18 +1,14 @@ -/* +/*- + * Top - a top users display for Berkeley Unix + * + * General (global) definitions * $FreeBSD$ */ -/* - * Top - a top users display for Berkeley Unix - * - * General (global) definitions - */ #ifndef TOP_H #define TOP_H #include - -#define Default_DELAY 2 /* Number of lines of header information on the standard screen */ extern int Header_lines; /* 7 */