Commit Graph

358 Commits

Author SHA1 Message Date
Daichi GOTO
324976739f top(1): fixed the empty output problem in non-interactive mode (-n, -b) regressed in r336028
PR:		229842
Reported by:	Ali Abdallah <aliovx@gmail.com>
Reviewed by:	eadler, cy
Approved by:	gnn (mentor)
Differential Revision:	https://reviews.freebsd.org/D16455
2018-07-27 01:20:34 +00:00
Daichi GOTO
cfb27362b1 top(1): forgot in r336160
Approved by:	gnn (mentor)
Differential Revision:	https://reviews.freebsd.org/D16452
2018-07-26 13:53:22 +00:00
Eitan Adler
10550f0b0a top(1): increase number of columns for memory
The original intention was 4 columns but with a usable a result. In
practice this was not the case. Increase the number of columns to 5
until humanize_number learns alternative ways of presenting the number.

Requested by:	many
Ref D15801
2018-07-25 14:05:17 +00:00
Mark Johnston
04354d577d Fix thread state summary line display after r334918. 2018-07-10 17:20:27 +00:00
Daichi GOTO
7452122499 top(1): rollback r335836
Encoding-specific processing introduced in r335836 is not recommended.
And doing getenv("LANG") and assuming an encoding based on it is a
very bad practice to internationalize software.

Submitted by:	hrs
Differential Revision:	https://reviews.freebsd.org/D16203
2018-07-10 03:49:48 +00:00
Daichi GOTO
5c48c1ee57 top(1): Fix the prompt bug and core dump problem in o / p mode that occurred by r336028
Reviewed by:	cy
Approved by:	gnn (mentor)
Differential Revision:	https://reviews.freebsd.org/D16174
2018-07-10 00:19:52 +00:00
Sean Bruno
9d5352cb63 r336028 changed next_msg to a char * from char [] of fixed size. Change
2nd argument of vsnprintf() to get the strlen of next_msg so that the
appropriate size is used.

Found with gcc.

/usr.bin/top/display.c: In function 'new_message':
/usr.bin/top/display.c:963:31: error:
argument to 'sizeof' in 'vsnprintf' call is the same expression as the
destination; did you mean to provide an explicit length?
[-Werror=sizeof-pointer-memaccess]
     vsnprintf(next_msg, sizeof(next_msg), msgfmt, args);

Reviewed by:	daichi
2018-07-06 13:22:44 +00:00
Daichi GOTO
0a59db87e3 Changed to eliminate the upper limit of command length displayed
by "-a" and expand to match terminal width

Reviewed by:	eadler
Approved by:	gnn (mentor)
Differential Revision:	https://reviews.freebsd.org/D16083
2018-07-06 12:07:06 +00:00
Konstantin Belousov
f87a5f036b top: do not fall to the thread name if kernel cache of the process
args is empty.

Instead, use kvm_getargv() unconditionally to obtain the process
arguments.  It means that one additional sysctl(2) is performed there.

Submitted by:	Thomas Munro
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D16111
2018-07-04 13:28:16 +00:00
Ruslan Bukin
c6dc704e84 Fix build: utf8strvisx() does signed data comparisons, but 'char' type
is unsigned in riscv GCC, so use guaranted signed char type.

Sponsored by:	DARPA, AFRL
2018-07-03 14:32:15 +00:00
Cy Schubert
4ee90e6e20 When toggling the display using the "m" command to toggle from 'cpu'
mode to 'io' mode, an artifact remains because the buffer is not
"finished" with a NULL terminator using sbuf_finish().

An example of this is, when the "m" command is entered, the title line
will contain COMMANDND instead of COMMAND. This commit fixes this.
2018-07-03 02:54:32 +00:00
Eitan Adler
39d2eb75fc top(1): permit infinite length for command
There isn't any need to limit the size of the screen. Utilities like
'less -S' don't have a (meaningful) limit anyways.  This also makes the
way to dynamically changing the column widths based on the screen width.
2018-07-01 19:44:29 +00:00
Daichi GOTO
4417ed2dbf top(1) - support UTF-8 display
Reviewed by:	eadler
Approved by:	gnn (mentor)
Differential Revision:	https://reviews.freebsd.org/D16006
2018-07-01 05:32:03 +00:00
Daichi GOTO
612e0030b6 top(1): increased the maximum length of command shown by "-a"
Reviewed by:	eadler
Approved by:	gnn (mentor)
Differential Revision:	https://reviews.freebsd.org/D16006
2018-06-27 02:55:30 +00:00
Eitan Adler
8d3f65e767 top(1): increase field with width for W/CPU column
This allows 3 digit CPU columns to look nice

Reported by:	feld
2018-06-24 13:14:04 +00:00
Eitan Adler
db36566345 top(1): Restructure printing of process states
This avoids the need to have separate buffers and calls to sprintf for
various calls.
2018-06-23 22:45:22 +00:00
Eitan Adler
0515b88e77 top(1): Convert process listing to sbuf too
This also fixes -mio with 'T' set (thread-id instead of process-id).

This can go further by removing the existing sprintf, and using sbuf
directly. This will be done in a followup commit.
2018-06-23 22:45:20 +00:00
Eitan Adler
ac8f40ea78 top(1): Use basename instead of a homegrown alternative 2018-06-23 22:45:18 +00:00
Eitan Adler
becfb1625c top(1): show CPU state breakdown on first run
There is no documented reason for this not to be shown on the first run.
I can't find any good reason, and it breaks batch mode.

PR:		218889
Submitted by:	"Jeremy C. Reed" <reed@reedmedia.net>
2018-06-23 03:17:11 +00:00
Eitan Adler
00abcb6acd top(1): increase warnings
top(1) now builds without cast-qual warnings, so remove the exemption
for that.

Tested with clang, gcc7, gcc9
2018-06-22 10:20:21 +00:00
Eitan Adler
8caf462ef6 top(1): garbage collect
- remove a now-unused function
- remove needless indirection of handle type
2018-06-22 10:17:12 +00:00
Eitan Adler
d9cf8a13ca top(1): increase size of 'C' column
On machines with more than 99 CPUs make room to display the entire
number.

Requested by:	cperciva
2018-06-22 10:17:10 +00:00
Eitan Adler
5c66dcc072 top(1): remove special handling of load > 5
When the load is "high" (an arbitrary value) top(1) previously moved the
cursor to the top-left of the screen as an acknowledgment. In practice,
on modern machines, even relatively slow ones, it looked more like a
glitch. Remove the logic.
2018-06-22 09:45:18 +00:00
Eitan Adler
51c834c490 top(1): reimplement header formatting as sbuf
The current header formatting is a giant format string that changes
global state during the format process.

Make the following changes:
- use sbuf to build up the header rather than use the above
pseudo-dynamic one
- Change name length to 10
- Reduce size of RES and SIZE by making humanize more aggressive
- Restore a version number line to the copyright. This may be required
by the copyright (and may not be; its unclear)

This is also a pre-req to implementing TOPCOLOR from newer versions of
top(1)

Discussed with:	allanjude, rpolka, danfe, rgrimes
Differential Revision: https://reviews.freebsd.org/D15801
2018-06-22 09:21:01 +00:00
Eitan Adler
57ad79afd6 top(1): behave as documented for -t
Show top itself by default, unless -t is specified.
2018-06-22 00:02:36 +00:00
Eitan Adler
3edda95c9d top(1): fix top -mio 2018-06-19 23:30:55 +00:00
Alan Somers
aa9d9bfa90 top(1): Fix Coverity warning
Don't call strerror on negative errnos

Reported by:	Coverity
CID:		976708
Reviewed by:	eadler
Differential Revision:	https://reviews.freebsd.org/D15909
2018-06-19 18:32:06 +00:00
Eitan Adler
cc11473037 top(1): correct assertion 2018-06-19 05:01:07 +00:00
Eitan Adler
e59ba74961 top(1): correct header in UP mode
Fix an oversight from r334869 which made the same change, but only for
SMP systems. This avoids a segfault while D15801 is being reviewed.

Reviewed by:	kevans
2018-06-19 04:18:23 +00:00
Eitan Adler
6bb0d5cf77 top(1): use more modern signal code
Rather than manually build signal masks use functions designed for that
reason. Also use sigprocmask instead of sigblock.
2018-06-18 02:06:16 +00:00
Eitan Adler
ef8dcce3c2 top(1): remove myself from top.1
I wrote some, but not enough for the man page.
2018-06-14 12:14:51 +00:00
Allan Jude
21e289d49b Fix top(1) support for displaying ZFS Compressed ARC statistics
Broken in r334514

sysctlbyname("vfs.zfs.compressed_arc_enabled", ...) would return ENOMEM
while trying to read the sysctl (a boolean_t) into a bool, which is too small.

Reviewed by:	jhb (on irc)
Sponsored by:	Klara Systems
2018-06-14 00:10:16 +00:00
Eitan Adler
f764243341 top(1): remove unneeded logic
- remove __pure annotations I added earlier for some functions. One
writes to the the arguments as "out" pointers. The
other reads from an array, which while const within the function might
be mutated externally.
- total_change is modified to be at 1, if previously 0, so no if check
is needed.
2018-06-13 11:12:52 +00:00
Eitan Adler
1de6384221 top(1): style(9)
- split return type from function name
- Sprinkle a __pure where possible.
2018-06-13 08:52:22 +00:00
Eitan Adler
d18626664a top(1): add myself to authors
At this point I've mucked enough with top(1) that all bugs should be
blamed on me rather than William LeFebvre.
2018-06-13 08:52:19 +00:00
Eitan Adler
c655e639c2 top(1): shift from atoi to non-deprecated function 2018-06-13 08:52:14 +00:00
Eitan Adler
704daa9b87 top(1): replace homegrown itoa with sprintf
Much of this should be inlined to the callsite, but leave it here for
now to make it easier to make it easier bisect later.
2018-06-13 08:52:12 +00:00
Eitan Adler
8e4b205ea5 top(1): format_time, format_k, etc.
- Use humanize_number for format_k and format_k2
- Fix some style nits in format_time
2018-06-13 08:52:09 +00:00
Eitan Adler
e7cb1c0776 top(1): format help more nicely
For entries that are duplicates present them nicely rather than showing
two identical help entries. For ' ' present it as SPC
2018-06-13 08:52:06 +00:00
Eitan Adler
59c50d8277 top(1): several small bugfixes and nits
- initialize all maybe uninitialized vars with bogus values. This shuts
up the compiler, and causes crashes if it changes later.
- mark noreturn as noreturn
- removed unused macro
- handle x_procstate as runtime rather than pre-processor
- avoid using void functions in condtionals

Tested with clang, gcc 7, gcc 9
2018-06-13 00:45:38 +00:00
Eitan Adler
0ff79d817c top(1): remove trailing whitespace 2018-06-12 07:31:59 +00:00
Eitan Adler
ccf22059e0 top(1): style and related
- style(9)
- remove now-defunct comments
- remove getuid check for low delay
- expand range of format_k
2018-06-12 07:14:12 +00:00
Eitan Adler
c8aa5e526f top(1): move command mapping to commands.c
This eliminates the difficult to follow mapping of a string list. It
moves numbers from "#define" into (more) debuggable enums. More
generally, it follows the trend of moving more data into a more central
mechanism.

The help output is a little worse: " " is not rendered well, and there
are duplicate entries, but that will be fixed in a followup.
2018-06-12 06:53:31 +00:00
Eitan Adler
fb7b896cd8 top(1): handle 0 in "digits" functions 2018-06-11 05:05:20 +00:00
Eitan Adler
a01160996b top(1): use modern interfaces for nice and related
- attempt and fail, rather than check for permission.
- use macro rather than explicit "-20"
2018-06-10 09:15:13 +00:00
Eitan Adler
1a8f56dd3a top(1): add command aliases; correct dumb support 2018-06-10 09:04:56 +00:00
Eitan Adler
561b0720cf top(1): use sys_signame instead of hard coding signals
This enables the removal of the signal.h awk script. Shamelessly stolen
from kill(1).
2018-06-10 09:00:01 +00:00
Eitan Adler
b26cf3d06c top(1): bring some structure to commands
Right now this is only used for help text but it'll eventually be used
to build up long options array, dispatch commands, etc.
2018-06-10 08:59:57 +00:00
Eitan Adler
4eef480b46 top(1): use correct word when displaying threads
PR:		182204
Reported by:	"Brodey Dover" <doverosx@gmail.com>
2018-06-10 06:33:49 +00:00
Eitan Adler
b4aadfd27e top(1): filter fewer warnings; clean up
- remove WARNS?=6. It is default
- we no longer have cast-qual problems
- remove unused macros
- remove unneeded casts
- add include guard for loadavg.h
2018-06-10 06:21:51 +00:00
Eitan Adler
da446b10ed top(1): permit sending signal with any case 2018-06-10 06:21:45 +00:00
Eitan Adler
468910cd7a 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.
2018-06-10 00:02:56 +00:00
Eitan Adler
6e0632db3d top(1): correctly reset per-cpu counters
I had changed this from a for loop to a memset during an earlier
cleanup. This change was incorrect so revert it.

While here, clean up

Reported by:	flo
2018-06-09 23:24:08 +00:00
Eitan Adler
ef436ca6a6 top(1): handle specific pids better
When told to watch a specific pid, don't filter idle, system, or self
processes. The summary at the top will still flip correctly though.
2018-06-09 23:08:02 +00:00
Eitan Adler
d73bfd43b2 top(1): implement additional missing long options 2018-06-09 22:30:10 +00:00
Eitan Adler
9d6cce02a7 top(1): initial pass to freebsdize the man page
The previous man page used many conventions not typical in FreeBSD.
Since we've forked top completely, convert the man page too.
2018-06-09 21:40:33 +00:00
Eitan Adler
c388909b8d top(1): Implement long options
This also documents some reserved or differing options from top's
original upstream.
2018-06-09 21:40:24 +00:00
Eitan Adler
dd0bdd6b45 top(1): allow starting with -T flag 2018-06-09 20:06:06 +00:00
Eitan Adler
e3225dcf12 top(1): correct header, align it.
THR is always 6 digits or longer. Now that the PID/THR change is
separated, use correct headers.

PR:		228823
Reported by:	Trond.Endrestol@ximalas.info
2018-06-09 02:47:02 +00:00
Eitan Adler
4e08f2f53c top(1): actually make change for tid vs pid 2018-06-09 02:18:15 +00:00
Eitan Adler
fc36f5a7cb top(1): use a different command to toggle tid vs pid
- By popular demand, implement a different switch ("T") for toggling
between thread id and process id.
- Add an assert that the size of command chars is as expected.
- Also clean up some messiness I found when implementing this.
- Further document the new flag.

Requested by:	flo, ronald-lists@klop.ws, bapt
PR:		139389 (for the record)
X-MFC-With:	r334474
2018-06-09 02:14:33 +00:00
Eitan Adler
4fb80c7008 top(1): remove some unneeded indirection 2018-06-08 02:03:51 +00:00
Eitan Adler
d408c8f742 top(1): fix several style & const related issues
- use parens for return
- put function names on newline
- sprinkle const where possible
2018-06-08 01:55:47 +00:00
Eitan Adler
59c8d5dc27 top(1): fix err again
I am amazed at my ability to get a one-line error reporting line wrong
thrice.
2018-06-06 07:13:27 +00:00
Eitan Adler
bca1b45bb1 top(1): make error message happy
We don't use a "size" variable, so just don't report it.

Reported by:	bapt
2018-06-06 06:42:12 +00:00
Eitan Adler
cda7a5d5ed top(1): some nitpicks
- prefer fully spelled names to "u_long"
- fix speeling
2018-06-04 05:27:00 +00:00
Eitan Adler
8d0d26767b top(1): include what you use
- Change headers to more closely match what we use
- use more standard functions instead of bzero, bcmp, bcopy
- Add myself to authors.

Tested with: base clang (amd64), gcc 9 (amd64), base clang (i386), base
gcc (mips)
2018-06-04 04:59:32 +00:00
Eitan Adler
5dc98aeeaa top(1): Prefer memcpy over bcopy 2018-06-04 04:59:24 +00:00
Eitan Adler
a9a99372d9 top(1): Use strsep instead of homegrown alternative
This replaces some complex, and not quite correct logic, with a more
common strsep pattern.

Reviewed by:	mmacy (older version)
2018-06-04 03:16:24 +00:00
Eitan Adler
eae589f1ce top(1): another pass of cleanup
- avoid the need to call a function to get size of known array. I'll
likely re-arrange some of the indirect in a later to avoid the magic
constants.
- use correct type
- add const
- replace caddr_t with void*. This corrects an alignment warning.
- remove duplicated include from immediately prior commit

Under base clang we're now down to:
- 3 warning in top.c, 1 warning in mahcine.c,  4 warning in display.c,
- 1 warning in utils.c

Tested with base clang, gcc7, gcc9, base gcc (mips)
2018-06-03 23:40:54 +00:00
Eitan Adler
9f8096e339 top(1): top warnings and cleanup
- Add const where helpful
- add missing 'static' for file-local functions
- use nitems where possible
- convert manual abort() to assert
- use strndup instead of homegrown version

Tested with clang, gcc7, and gcc9
2018-06-03 22:42:54 +00:00
Eitan Adler
a2cda47ac3 top(1): restore size for kern.cp_times
Restore last minute change that broke top(1).
2018-06-03 13:41:23 +00:00
Eitan Adler
c5484668f1 top(1): Only use NO_WERROR for base gcc
This is what was intended. If statements are hard.
2018-06-03 06:02:31 +00:00
Eitan Adler
01a55f006a top(1): partial revert of r334517
In fixing issues with uid > INT_MAX, I broke the uid without username
case. The latter is more important so return the old state.

Discussed with:	allanjude
2018-06-03 05:20:11 +00:00
Eitan Adler
b7128a09ce top(1): remove chdir to /
While this came out of a conversation in IRC, it turn out that some
people don't like it. Since this was a courtesy feature, just remove it.
2018-06-03 05:07:46 +00:00
Eitan Adler
1d5b01e66e top(1): use greater warnings
One of the downsides of using numeric WARNS is that if we only have a
single type of issue we get no protection from other changes.  For
example, we got no warning for missing variable declaration, due to
the issues with "const".

For this utility, explicitly list out the warnings which are failing.
They should still be fixed, so only reduce them to warning instead of
error.

Tested with: clang base (amd64, i386), gcc6, gcc7, gcc9, gcc base (mips)
2018-06-03 05:07:39 +00:00
Eitan Adler
d0bb69dc07 top(1): misc minor improvements
- use bool instead of int [0]
- use calloc correctly [0]
	(this also caught an incorrect sizeof argument) [1]
- use size_t over int [2]
- correct style

Reported by:	pfg [0], scan-build [1], gcc [2]
2018-06-03 02:58:53 +00:00
Eitan Adler
c51e28f46f top(1): Fix two speeling errors I introduced 2018-06-02 22:12:57 +00:00
Eitan Adler
f32efe0205 top(1): chdir to / as init; remove unneeded comment
- chdir to / to allow unmounting of wd
- remove warning about running top(1) as setuid. If this is a concern we
should just drop privs instead.
2018-06-02 22:06:27 +00:00
Eitan Adler
4fedcd4983 top(1): cleanup memory allocation and warnings
- Prefer calloc over malloc. This is more predicable and we're not in a
performance sensitive context. [1]
- Remove bogus comment (obsolete from prior commit). [2]
- Remove void casts and type casts of NULL
- Remove redundant declaration of 'quit'
- Add additional const

Reported by:	kib [1], vangyzen [2]
2018-06-02 21:40:45 +00:00
Roman Bogorodskiy
51b29cb7b3 top: add -p option and p command to only show a single process
Allow to show only a single process specified by PID. This could
be done either by running top like 'top -p PID' or using the 'p' command
inside top.

Reviewed by:	eadler
Approved by:	eadler
Obtained from:	OpenBSD
Differential Revision:	https://reviews.freebsd.org/D15501
2018-06-02 15:52:18 +00:00
Eitan Adler
b274c68a20 Use stpcpy instead of home grown solution 2018-06-02 08:46:09 +00:00
Eitan Adler
2c1fdbac13 top(1): remove wrapper around putchar
This appears to have been written for portability which we no longer
need.
2018-06-02 07:44:53 +00:00
Eitan Adler
960a7f3960 top(1): const poison part 2
Further reduce the number of warnings emitted by gcc.
2018-06-02 07:44:50 +00:00
Eitan Adler
66b3f031f0 top(1): const poison
top(1) has a number of issues with writing to const strings. Begin
helping this along by marking easy cases as const.
2018-06-02 04:37:37 +00:00
Eitan Adler
0059e7102f top(1): clean up a bit
- remove unused defines
- use standard defines for STDOUT
- don't cast for memset
- avoid using (void) cast
2018-06-02 04:20:42 +00:00
Eitan Adler
cffee2bc5b top(1): help scan-build along a bit
Teach scan-build that some arrays are larger than zero, and thus not to
warn.
2018-06-02 04:08:52 +00:00
Eitan Adler
1978939544 top(1): Use uid_t for uid rather than 'int'
Remove unneeded define while here.
2018-06-02 03:54:50 +00:00
Eitan Adler
f4d9a8de00 top(1): Remove now-invalid NOTE 2018-06-02 03:33:02 +00:00
Eitan Adler
3798694c01 top(1): avoid casting malloc 2018-06-02 03:31:14 +00:00
Eitan Adler
0b2f6ed144 top(1): Use standard boolean rather than homegrown alternative 2018-06-02 03:25:15 +00:00
Eitan Adler
220e4623aa top(1): remove two unneeded headers 2018-06-02 00:02:27 +00:00
Eitan Adler
f6234b51bf top(1): ansify, style(9). and nits
- Prefer using ansi prototypes rather than C prototypes
- Keep type on separate line from name of function
- Try to keep things const where possible. This will help get to WARNS=6
- switch to "bool" where it makes sense
2018-06-02 00:02:15 +00:00
Eitan Adler
937499dcb1 top(1): Display of TID when using 'H' flag
Some users prefer seeing the TID when viewing individual threads. This
makes sense as the PID will be the same for multiple entries. An attempt
was made to include both, but there is insufficient room. As such, using
the TID.

While here, rename the header variables to be more understandable.

Discussed with:	mmacy
Reported on:	2009-10-07
2018-06-01 05:51:40 +00:00
Eitan Adler
dbcdf411a1 top(1): increase size of 'status' buffer
This corrects a warning issues by gcc9:
/srv/src/freebsd/head/usr.bin/top/machine.c:988:22: warning: '%5zu'
directive writing between 5 and 20 bytes into a
 region of size 15 [-Wformat-overflow=]
     sprintf(status, "?%5zu", state);
2018-05-22 07:56:58 +00:00
Eitan Adler
bc875b45c5 top(1): unbreak build with gcc7; fix varargs
- use correct function for varargs argument
- allow build to complete with gcc7 at current WARNS

Reported by:	jhibbits, ian
2018-05-22 02:13:04 +00:00
Eitan Adler
6ffc72df9d top(1): fix build
Remove 'top.local.hs'. This was not noticed since
/srv/obj/fbsd/srv/src/freebsd/svn/head/amd64.amd64/usr.bin/top/top.local.h
existed locally on my machine despite "make clean". Only fully removing
the objdir allowed me to observe the error directly.

Pointyhat to:	me
2018-05-21 09:43:50 +00:00
Eitan Adler
3c9ec0a580 top(1): clean up some "const" related warnings
This leaves at WARNS=6:
35 warnings in top.c
88 warnings in machine.c

all of which are either "incompatible-pointer-types-discards-qualifiers"
or "cast-qual"
2018-05-21 09:32:52 +00:00
Eitan Adler
1b7645c629 top(1): modernize a bit; reduce warnings
- Replace caddr_t with "void *". This reduces
the number of warnings at WARNS=6
- use "static" where possible
- sprinkle const where possible

This leaves at WARNS=6:
35 warnings in top.c
88 warnings in machine.c
7 warnings in commands.c

all of which are either "incompatible-pointer-types-discards-qualifiers"
or "cast-qual"
2018-05-21 09:25:21 +00:00
Eitan Adler
dfa5eb70ae Add missing va_end
Reported by:	andrew
2018-05-21 09:21:42 +00:00