History log of /freebsd-current/usr.bin/top/top.c
Revision Date Author Comments
# b3e76948 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: two-line .h pattern

Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/


# 2fc08940 02-Apr-2022 Gordon Bergling <gbe@FreeBSD.org>

top(1): Fix a typo in a source code comment

- s/accomodate/accommodate/

MFC after: 3 days


# 82d0f865 18-Nov-2021 Mateusz Piotrowski <0mp@FreeBSD.org>

top: Sort flags in usage message

While here, fix the indentation of the second line in the message.

MFC after: 3 days


# 4ccbbe5f 07-Sep-2021 John Grafton <john.grafton@gmail.com>

top(1): indicate how to reset grep string

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/536/files


# a00d703f 16-Jun-2021 John Grafton <john.grafton@gmail.com>

top(1): support command name and argument grepping

Obtained from: OpenBSD
Reviewed by: imp@
Pull Request: https://github.com/freebsd/freebsd-src/pull/479


# fc8ae86a 20-Dec-2019 Philip Paeps <philip@FreeBSD.org>

top: display battery capacity remaining

Submitted by: Antranig Vartanian <antranigv@freebsd.am>
Reviewed by: imp, philip
Differential Revision: https://reviews.freebsd.org/D22871


# fc4ac32f 27-Sep-2019 Dimitry Andric <dim@FreeBSD.org>

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


# a6f721ec 27-Sep-2019 Dimitry Andric <dim@FreeBSD.org>

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 after: 3 days


# b1de37fa 20-Sep-2019 Daichi GOTO <daichi@FreeBSD.org>

top(1): support multibyte characters in command names (ARGV array)
depending on locale.

- add setlocale()
- remove printable() function
- add VIS_OCTAL and VIS_SAFE to the flag of strvisx() to display
non-printable characters that do not use C-style backslash sequences
in three digit octal sequence, or remove it

This change allows multibyte characters to be displayed according to
locale. If it is recognized as a non-display character according to the
locale, it is displayed in three digit octal sequence.

Reference:
https://www.mail-archive.com/svn-src-all@freebsd.org/msg165751.html
https://www.mail-archive.com/svn-src-all@freebsd.org/msg165766.html
https://www.mail-archive.com/svn-src-all@freebsd.org/msg165833.html
https://www.mail-archive.com/svn-src-all@freebsd.org/msg165846.html
https://www.mail-archive.com/svn-src-all@freebsd.org/msg165891.html

Submitted by: hrs
Differential Revision: https://reviews.freebsd.org/D16204


# d0f687d3 10-Feb-2019 Dimitry Andric <dim@FreeBSD.org>

Fix multiple warnings in usr.bin/top about discarded qualifiers from
both clang and gcc, by either constifying variables, or when that is not
possible, using __DECONST.

MFC after: 1 week


# 61ef814f 18-Jan-2019 Justin Hibbits <jhibbits@FreeBSD.org>

Fix top(1) long options handling

getopt_long(3) requires the long options be terminated by a NULL block.
Without the terminator, an invalid long option results in a segmentation
fault.

Reported by: Brandon Bergren
MFC after: 1 week


# e7a0ad24 30-Nov-2018 Mark Johnston <markj@FreeBSD.org>

Add missing display messages when toggling modes.

PR: 233667
Submitted by: James Wright <james.wright@jigsawdesign.com>
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D18331


# 17be5f23 22-Aug-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): Use warnx and errx instead of fprintf

This also makes make "-v" exit without error, since it isn't.


# eeb147d5 22-Aug-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): issue warning on invalid delay

When top -sH is run it continually updates. It should issue an warning
instead.

Reported by: jmg
PR: 230803


# 74521224 09-Jul-2018 Daichi GOTO <daichi@FreeBSD.org>

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


# 4417ed2d 30-Jun-2018 Daichi GOTO <daichi@FreeBSD.org>

top(1) - support UTF-8 display

Reviewed by: eadler
Approved by: gnn (mentor)
Differential Revision: https://reviews.freebsd.org/D16006


# becfb162 22-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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>


# 5c66dcc0 22-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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.


# 57ad79af 21-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): behave as documented for -t

Show top itself by default, unless -t is specified.


# cc114730 18-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): correct assertion


# 6bb0d5cf 17-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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.


# 59c50d82 12-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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


# 0ff79d81 12-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): remove trailing whitespace


# ccf22059 12-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): style and related

- style(9)
- remove now-defunct comments
- remove getuid check for low delay
- expand range of format_k


# c8aa5e52 12-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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.


# a0116099 10-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): use modern interfaces for nice and related

- attempt and fail, rather than check for permission.
- use macro rather than explicit "-20"


# b4aadfd2 10-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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


# 468910cd 09-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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.


# ef436ca6 09-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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.


# d73bfd43 09-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): implement additional missing long options


# c388909b 09-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): Implement long options

This also documents some reserved or differing options from top's
original upstream.


# dd0bdd6b 09-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): allow starting with -T flag


# fc36f5a7 08-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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


# d408c8f7 07-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): fix several style & const related issues

- use parens for return
- put function names on newline
- sprinkle const where possible


# 8d0d2676 03-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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)


# eae589f1 03-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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)


# 9f8096e3 03-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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


# 01a55f00 02-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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


# b7128a09 02-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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.


# c51e28f4 02-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): Fix two speeling errors I introduced


# f32efe02 02-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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.


# 51b29cb7 02-Jun-2018 Roman Bogorodskiy <novel@FreeBSD.org>

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


# 19789395 01-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): Use uid_t for uid rather than 'int'

Remove unneeded define while here.


# 0b2f6ed1 01-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): Use standard boolean rather than homegrown alternative


# f6234b51 01-Jun-2018 Eitan Adler <eadler@FreeBSD.org>

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


# bc875b45 21-May-2018 Eitan Adler <eadler@FreeBSD.org>

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


# 6ffc72df 21-May-2018 Eitan Adler <eadler@FreeBSD.org>

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


# 1b7645c6 21-May-2018 Eitan Adler <eadler@FreeBSD.org>

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"


# 00157b4c 21-May-2018 Eitan Adler <eadler@FreeBSD.org>

Revert r333969 which contained one too many changes


# bfb79c2c 21-May-2018 Eitan Adler <eadler@FreeBSD.org>

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
72 warnings in machine.c
5 warnings in commands.c

all of which are either "incompatible-pointer-types-discards-qualifiers"
or "cast-qual"


# 5ef89dbf 20-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): further unconditionally assume we're on FreeBSD


# 1d6a4ba3 20-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): build with WARNS=3

This fixes everything but
-Wincompatible-pointer-types-discards-qualifiers


# a5ca08ed 20-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): fix several more warnings


# fcfaa473 20-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): pull function declarations and externs into headers


# 666cf873 20-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): clean much of WARNS=3 issues

There is still one glaring issue: new_message is not a protoype, but
can't be trivially converted since it uses K&R style var-args.


# 668af25d 20-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): pull configuration directly into header files

This sets configuration variables directly in the various header files,
avoiding the need to have special logic in our Makefile to build the
header.


# 4b9ca404 20-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): set max username length based on system constant

This changes previous behavior of calculating it at startup based on
the current max username length.

This is done because:
- it is in theory possible for the max length to change at run-time
(e.g., a new user is added after top starts running)
- on machines with many users this delays startup significantly

PR: 20799
PR: 89762
Reported by: ob@e-Gitt.NET
Reported by: wkwu@Kavalan.csie.NCTU.edu.tw
Reported on: 2000-08-23 and 2005-11-30


# b3c88c28 19-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): Quiesce several warnings

This is all warnings at level six (6) that are not
char-subscripts, incompatible-pointer-types,
sign-compare, switch, int-conversion,
missing-variable-declarations, cast-qual, cast-align

Some warnings that are fixed by this commit are:
shadow, strict-prototypes, missing-prototypes, pointer-arith,
unused-parameter, unused-const-variable, and several others


# 98c299e0 19-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): remove use of 'register' keyword

This keyword is meaningless is obscures future diffs that help clear up
warnings in top.


# caee4883 19-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): unconditionally assume we are running on FreeBSD

This allows us to remove a special header and more specifically just the
system headers we want.


# 8a133278 19-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): unconditionally provide 'FreeBSD' as a version


# 946e91ab 19-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): assume that we're building on FreeBSD

This allows us to avoid the ifdefs that we set unconditionally.


# 3be6ef06 19-May-2018 Eitan Adler <eadler@FreeBSD.org>

top(1): Migrate top to usr.bin

We've been maintaining top(1) for a long time, and the upstream
hasn't existed/been used in similarly as long. Make it clear that we own
top(1)

Tested with 'make universe'. Everything passed except MIPS which failed
for unrelated reasons. Install also tested for amd64.

Reviewed by: sbruno
No objections: imp, mmacy
Differential Revision: https://reviews.freebsd.org/D15387