Date: Sun, 10 Jun 2018 00:02:56 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334906 - head/usr.bin/top Message-ID: <201806100002.w5A02uBP012215@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <unistd.h> - -#define Default_DELAY 2 /* Number of lines of header information on the standard screen */ extern int Header_lines; /* 7 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806100002.w5A02uBP012215>