]> git.ipfire.org Git - thirdparty/iproute2.git/commit
ss: use COLUMNS from the environment, if TIOCGWINSZ fails
authorDragan Simic <dsimic@manjaro.org>
Tue, 21 May 2024 10:04:52 +0000 (12:04 +0200)
committerDavid Ahern <dsahern@kernel.org>
Wed, 29 May 2024 15:58:11 +0000 (15:58 +0000)
commit900162c09e4dcf2394343ac4a478591f6d8f4473
tree5009d5270e2992a54facf69499c64c34fc5f0c0b
parent3a84a49a53e68a154089debf3a6d9b59f0a49e5a
ss: use COLUMNS from the environment, if TIOCGWINSZ fails

Use the COLUMNS environment variable [1] when determining the screen width,
if using TIOCGWINSZ isn't possible or if it fails.  This allows better use
of the available horizontal screen space in certain scenarios, and makes
the produced outputs more readable, as described further below.

All major shells can maintain the COLUMNS variable according to the current
screen size, [2][3][4] but this shell variable isn't actually an environment
variable, i.e. it doesn't get exported to the shell subprocesses by default.
For example, no COLUMNS environment variable reaches ss(8) when it's executed
as part of a shell pipeline or inside a shell script.

Though, users can opt to export the COLUMNS variable by hand, or they can
rely on some other utilities to do that for them.  A good example of such
utilities is watch(1) that exports COLUMNS as an environment variable to
the processes it executes. [5]  Using ss(8) together with watch(1) is rather
useful, and honoring the exported COLUMNS variable makes the outputs produced
by ss(8) in this scenario more readable.

The behavior of shells, which don't export the COLUMNS variable by default,
makes this change safe in the sense of not affecting the usual shell pipeline
workflows or various shell scripts that use ss(8).

[1] https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/basedefs/V1_chap08.html
[2] https://man.archlinux.org/man/bash.1.en#COLUMNS
[3] https://man.archlinux.org/man/tcsh.1.en#Terminal_management_(+)
[4] https://man.archlinux.org/man/zshall.1.en#Configuration
[5] https://gitlab.com/procps-ng/procps/-/blob/master/NEWS?ref_type=heads#L623

Signed-off-by: Dragan Simic <dsimic@manjaro.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
misc/ss.c