opnsense-src/bin
Olivier Certner 7aa2f48267
ps(1): Remove not-explicitly-requested columns with duplicate data
Before this change, when stacking up more columns in the display through
command-line options, if user requested to add some "canned" display
(through options '-j', '-l', '-u' or '-v'), columns in it that were
"duplicates" of already requested ones (meaning that they share the same
keyword, regardless of whether their headers have been customized) were
in the end omitted.

However, this mechanism did not work the other way around, i.e.,
requesting some canned display(s) first and then adding some columns
that are duplicates (through '-o' or '-O') would not remove them from
the canned display.  Additionally, it did not take into account keyword
aliases (which also lead to displaying the same information).

This whole mechanism of removing columns from requested canned displays
when there are duplicates is useful in a number of scenarios:
1. When one wants the columns of a canned display, but with some of them
   in a different order and at the edges of the bulk.  This needs the
   change here to move columns after the bulk (previously, only moving
   them before the bulk would work).
2. To combine multiple canned displays to get more information without
   repeating common columns. This part has been working before and
   this behavior is unchanged.
3. In combination with requesting a canned display and additional
   columns after it, ensure that a single COMMAND column appears at the
   end of the display (to benefit from the fact that a last COMMAND
   column can extend further to the right).

Point 2 above implies that, when multiple canned displays are requested,
we should keep the leftmost column with same keyword.  However, columns
requested explicitly by '-o' have priority (as the natural extension of
point 1's behavior before this change), and in this case all matching
columns in canned displays must be suppressed.

To this end, when adding requested options to the display's list, we
stop trying to find an earlier matching column (which is incidentally
a O(n²) algorithm).  Instead, we do a first pass over all requested
options once they have all been added to the display's list (in
scan_vars()).  For each keyword, we note if it was requested at least
once explicitly (through '-o' or '-O'), in addition to setting
'needuser' and 'needcomm' (as before).  Then, a second pass decides
whether to keep each column.  A column is removed if it should not be
kept absolutely (i.e., it wasn't specified via '-o' or '-O') and there
is either a matching column that must be kept (determined during the
first pass), or we have seen one already (earlier canned displays take
precedence).

Matching columns are in fact not only those that have same keywords, but
also those that have keywords determined to be aliases to each other.
Some previous commits ensured that this determination is O(1) and in
practice just a few assembly instructions.

find_varentry() has been kept although its last caller has been removed
as next commit will reintroduce a call to it.

MFC after:      3 days
Relnotes:       yes
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D49612
Differential Revision:  https://reviews.freebsd.org/D49613 (manual page)

(cherry picked from commit cd768a8406)
2025-05-01 21:37:04 +02:00
..
cat cat: Check for lack of success rather than a specific failure. 2024-05-14 08:58:40 +02:00
chflags chflags(1): obey siginfo request on chflagsat(2) failure 2024-02-06 02:37:37 +02:00
chio Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
chmod Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
cp cp: Improve error messages. 2025-04-20 08:00:29 +00:00
cpuset Use proper convention for relative path linking 2023-08-18 04:20:32 -07:00
csh csh: Remove gethost dependency on tc.const.h 2025-02-18 12:19:16 -05:00
date date: Fix a few nits. 2024-10-06 09:12:24 +00:00
dd Remove $FreeBSD$: one-line bare tag 2023-08-16 11:55:20 -06:00
df Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
domainname Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
echo Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
ed Remove $FreeBSD$: one-line bare tag 2023-08-16 11:55:20 -06:00
expr Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
freebsd-version bsdinstall: rename "Live CD" to "Live System" 2024-01-07 14:31:10 -05:00
getfacl Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
hostname hostname(1): Add test cases 2024-02-08 14:02:33 +08:00
kenv Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
kill kill.1: mention special meaning of PGID as a PID 2025-01-21 02:25:59 +02:00
ln faccessat(2): Honor AT_SYMLINK_NOFOLLOW 2024-09-26 09:13:50 -04:00
ls ls: Release resources before returning from traverse() 2025-01-28 16:00:12 +00:00
mkdir Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
mv mv: Set file flags after setting file times 2024-04-25 09:20:16 -04:00
nproc nproc.1: Fix "first appeared in" details 2023-06-02 18:53:55 +02:00
pax pax: Clear arcn in each read function. 2024-08-01 18:15:57 +02:00
pkill pkill tests: Fix pkill usage in the pkill -x test 2025-04-06 13:54:03 +00:00
ps ps(1): Remove not-explicitly-requested columns with duplicate data 2025-05-01 21:37:04 +02:00
pwait Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
pwd Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
realpath Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
rm Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
rmail Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
rmdir Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
setfacl Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
sh sh(1): Replace recommendation of use of -e with a note 2025-03-15 15:00:17 +01:00
sleep Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
stty (s)tty: add support for IUTF8 input flag 2023-10-21 17:28:34 +03:00
sync sync.8: Document that the "sync dance" is not a thing 2024-04-28 20:28:43 +02:00
test Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
tests Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
timeout timeout(1): Add -v/--verbose option to show diagnosis info 2025-01-19 20:30:13 +01:00
uuidgen pkgbase: Move uuidgen to runtime package 2023-10-18 16:36:30 +02:00
Makefile Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
Makefile.inc Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00