lib/pager: Apply pager-specific fixes only when needed
Currently defined output filter quirk fixes and environment variable
tweaks apply to less(1) only, so let's don't apply them when the pager
is actually configured to something else.
While there, rename the less(1)-specific callback function to make
clear what it applies to, and to make adding any posible additional
pager-specific callback functions a bit easier.
It's quite common to have options in the commands specified in the
PAGER environment variable, to customize the behavior of the configured
output filter. For example, someone might want to include the "-X"
option when less(1) is configured as the output filter, or might want
to specifically not include it, depending on the personal preferences.
For example, man(1), git(1) and bat(1) already allow and properly handle
the presence of any options in the configured output filter commands,
which assures that it's fine to do the same in util-linux.
Here's also a quotation from the description of the man(1) utility that
describes the PAGER environment variable, as found in The Single UNIX
Specification, version 4:
PAGER
Determine an output filtering command for writing the output
to a terminal. Any string acceptable as a command_string operand
to the sh -c command shall be valid. When standard output is
a terminal device, the reference page output shall be piped
through the command. If the PAGER variable is null or not set,
the command shall be either more or another paginator utility
documented in the system documentation.
This quotation just confirms, rather formally, that allowing options
in the output filter commands is a perfectly valid thing to do.
While there, perform a couple of minor cleanups as well, to make the
formatting of the code a tiny bit more consistent, and to slightly
improve one of the logged debug messages.
Karel Zak [Mon, 10 Jul 2023 10:33:21 +0000 (12:33 +0200)]
Merge branch 'lsfd--lock-flags-in-XMODE-column' of https://github.com/masatake/util-linux
* 'lsfd--lock-flags-in-XMODE-column' of https://github.com/masatake/util-linux:
test: (lsfd): add a case for l and L flags in XMODE column
test: (mkfds::ro-regular-file) add a parameter for a read lease
test: (mkfds::make-regular-file) add a parameter for file locking
lsfd: add flags, [-lL], representing file lock/lease states to XMODE column
test: (mkfds::make-regular-file) add a parameter for making the new file readable
test: (mkfds::make-regular-file) add a parameter for writing some bytes
test: (mkfds::make-regular-file) make 'fd' local variable reusable
test: (mkfds::make-regular-file) delete the created file when an error occurs
test: (lsfd::column-xmode): add mising "wait" invocation
lsfd: add flags, [-lL], representing file lock/lease states to XMODE column
The flags hide the details of locking: methods for locking (including
lease), mandatory or advisory, and ranges. The flags can be used only
for distinguishing three states: not locked, read (or shared) locked,
or write (or exclusive) locked.
Karel Zak [Mon, 3 Jul 2023 10:47:08 +0000 (12:47 +0200)]
Merge branch 'clock' of https://github.com/t-8ch/util-linux
* 'clock' of https://github.com/t-8ch/util-linux:
lsclocks: new util to interact with system clocks
lib/timeutils: implement timespec formatting
lib/timeutils: implement nanosecond formatting
lib/timeutils: constify some arguments
utmpdump: validate subsecond granularity
Karel Zak [Mon, 3 Jul 2023 10:41:04 +0000 (12:41 +0200)]
Merge branch 'lsfd--xmode' of https://github.com/masatake/util-linux
* 'lsfd--xmode' of https://github.com/masatake/util-linux:
lsfd: add 'D' flag for representing deleted files to XMODE column
lsfd: introduce XMODE column, extensible variant of MODE
test: (lsfd) add a subcase for testing NAME column for a deleted file
test: (lsfd) add a case for testing DELETED column
test: (mkfds) add "make-regular-file" factory
Karel Zak [Mon, 3 Jul 2023 10:38:48 +0000 (12:38 +0200)]
Merge branch 'lsfd--misc-tun' of https://github.com/masatake/util-linux
* 'lsfd--misc-tun' of https://github.com/masatake/util-linux:
tests: (lsfd) add a case testing TUN.IFACE column
tests: (mkfds) add a factor for opening tun device
lsfd: add TUN.IFFACE, a column for interfaces behind tun devices
lsfd: (refactor) move miscdev specific code to cdev_misc_ops
lsfd: (refactor) make the way to handle character devices extensible
lsfd: (refactor) introduce a content data type for char devices
Karel Zak [Mon, 3 Jul 2023 10:30:43 +0000 (12:30 +0200)]
Merge branch 'wip/rishi/libmount-src-libmount.h-MNT_ERR_APPLYFLAGS-docs' of https://github.com/debarshiray/util-linux
* 'wip/rishi/libmount-src-libmount.h-MNT_ERR_APPLYFLAGS-docs' of https://github.com/debarshiray/util-linux:
libmount: update documentation for MNT_ERR_APPLYFLAGS
Debarshi Ray [Thu, 29 Jun 2023 11:04:41 +0000 (13:04 +0200)]
libmount: update documentation for MNT_ERR_APPLYFLAGS
The implementation using the new FD based mount kernel API (ie.,
fsconfig/fsopen) uses MNT_ERR_APPLYFLAGS for failed mount_setattr(2)
calls, which involves more mount attributes (eg., MOUNT_ATTR_RDONLY,
MOUNT_ATTR_NOSUID, etc.) in addition to the MS_PROPAGATION flags (eg.,
MS_SHARED, MS_UNBINDABLE, etc.).
Note that mount_setattr(2) is part of the new FD based mount kernel API,
and is not used by the classic mount(2) based version.
Enter the cgroup namespace of target process without option -c:
$ sudo ./nsenter -C -U -t 216054 sh -c "cat /proc/self/cgroup"
0::/../../../../session-899.scope
Enter the cgroup namespace of target process with option -c:
$ sudo ./nsenter -c -C -U -t 216054 sh -c "cat /proc/self/cgroup"
0::/
Reviewed-by: Karel Zak <kzak@redhat.com> Reviewed-by: Thomas Weißschuh <thomas@t-8ch.de> Signed-off-by: u2386 <hugo.cavan2386@gmail.com>
Karel Zak [Mon, 26 Jun 2023 11:25:11 +0000 (13:25 +0200)]
cfdisk: fix menu behavior after writing changes
Florian wrote:
after a successful write, cfdisk remains on the "Write" cursor and
furthermore when navigating to "Quit" will continue to show
"...without writing changes", despite there were writes. This patch
addresses that.
Based on patch from Florian Zimmermann <florian.zimmermann@gmail.com>
Edward Chron [Fri, 23 Jun 2023 01:31:31 +0000 (18:31 -0700)]
dmesg: -r LOG_MAKEPRI needs fac << 3
Submission to Project: util-linux
Open Incident: #2325 at github.com/util-linux/util-linux/issues/2325
Component: util-linux/sys-utils
File: dmesg.c
Code level patch applied against: 2.39 - latest code pulled from
git.github.com:util-linux/util-linux.git
BUG: The facility field passed to macro from /usr/include/sys/syslog.h
LOG_MAKEPRI(fac, pri) by dmesg -r needs to have fac argument
shifted 3 bit to the left to return a valid raw valid. The lower
3 bits for a raw value are used by the loglevel priority (pri)
field, so the facility bits can only occupy the bits above the
bits used to hold the pri field value.
The dmesg -r command produces the incorrect output for the raw value
for the or'ed combination of the facility | loglevel priority that gets
produced by the LOG_MAKEPRI macro. That macro is defined as:
#define LOG_MAKEPRI(fac, pri) ((fac) | (pri))
which is defined in the current glibc code in /usr/include/sys/syslog.h
and is used only in the dmesg -r (raw output option) command to form the
raw value for facility or'ed with loglevel priority and displayed as:
<#>[#######.######] ...
where the # in <#> contains the output from the LOG_MAKEPRI macro.
The lower 3 bits are reserved for the loglevel priority 0-7
and the bits above that are for the facility value, so the facility
index should be shifted to the left three bits and or'ed with the
loglevel priority.
In the glibc file: /usr/include/sys/syslog.h the macro LOG_MAKEPRI is
defined as:
#define LOG_MAKEPRI(fac, pri) ((fac) | (pri)
and returns the wrong facility and loglevel priority values, ideally it
should be defined as:
We checked with glibc developement and the LOG_MAKEPRI macro is correct
as is and can't be changed as it used by *BSD as is so the solution for
dmesg -r is to shift the facility index left by 3 bits as input to the
LOG_MAKEPRI macro. That is what glibc development recommended.
(For reference, see glibc bugzilla Bug 30563)
We can front end the LOG_MAKEPRI macro with a macro that shifts the
facility by the needed 3 bits which we've added to dmesg.c:
-bash-4.2# dmesg -r | grep "Test Message Facility"
<7>[ 495.317239] Test Message Facility 8 Loglevel 6
<7>[ 503.340779] Test Message Facility 8 Loglevel 7
<7>[ 643.374764] Test Message Facility 24 Loglevel 6
<7>[ 657.165117] Test Message Facility 24 Loglevel 7
However, if we run the dmesg -r command using the new front end macro
LOG_RAW_FAC_PRI(fac, pri) we do get the correct output:
Here is the corrected dmesg -r output:
-------------------------------------
-bash-4.2# dmesg -r | grep "Test Message Facility"
<14>[ 495.317239] Test Message Facility 8 Loglevel 6
<15>[ 503.340779] Test Message Facility 8 Loglevel 7
<30>[ 643.374764] Test Message Facility 24 Loglevel 6
<31>[ 657.165117] Test Message Facility 24 Loglevel 7
shifting the facility index value by 3 bits in the LOG_RAW_FAC_PRI macro
provides the correct ouput as shown. All the other commands produce the
same output so now they are all in agreement.
Signed-off-by: Ivan Delalande <colona@arista.com> Signed-off-by: Edward Chron <echron@arista.com>
Karel Zak [Mon, 26 Jun 2023 09:48:24 +0000 (11:48 +0200)]
Merge branch 'lsfd--fix-separators-for-json-output-cleanup' of https://github.com/masatake/util-linux
* 'lsfd--fix-separators-for-json-output-cleanup' of https://github.com/masatake/util-linux:
lsfd: fix specifying wrong JSON typs when building the help message
tests: (lsfd) add a case for verifying ENDPOINTS column output in JSON mode
Karel Zak [Mon, 26 Jun 2023 09:45:50 +0000 (11:45 +0200)]
Merge branch 'PR/libmount-optstr-sync' of github.com:karelzak/util-linux-work
* 'PR/libmount-optstr-sync' of github.com:karelzak/util-linux-work:
libmount: add sample to test fs and context relation
libmount: fix sync options between context and fs structs
Thomas Weißschuh [Wed, 21 Jun 2023 12:26:05 +0000 (14:26 +0200)]
tests: (run.sh) detect builddir from working directory
This makes it easier to run test.sh from the build directory as
everything will work without any parameters irrespective of the build
directories name.
igo95862 [Sun, 26 Mar 2023 15:04:11 +0000 (21:04 +0600)]
Add `--user-parent` option to nsenter
When this option is used nsenter will fetch the parent user
namespace from any namespace file descriptors available.
It can be combined with existing `--user` option in which case
the parent user namespace will be fetched from the user namespace
and replace it.
The usecase of this option is when a user namespace that owns
the other type namespaces we want to switch to is not actually
bound to any process. Without using ioctl it is impossible to
acquire namespace file descriptor. For example, bubblewrap
`bwrap` command creates unbinded user namespace when `--dev`
option is used.
Karel Zak [Thu, 22 Jun 2023 12:26:09 +0000 (14:26 +0200)]
Merge branch 'lsfd--fix-separators-for-json-output' of https://github.com/masatake/util-linux
* 'lsfd--fix-separators-for-json-output' of https://github.com/masatake/util-linux:
lsfd.1.adoc: fix a typo
lsfd: use ARRAY_STRING and ARRAY_NUMBER json types in some columns
lsfd: use \n as the separator in INOTIFY.INODES and INOTIFY.INODES.RAW columns
lsfd: use \n as the separator in EVENTPOLL.TFDS column
lsfd: (filter) weakly support ARRAY_STRING and ARRAY_NUMBER json types
Karel Zak [Thu, 22 Jun 2023 11:11:57 +0000 (13:11 +0200)]
libmount: fix sync options between context and fs structs
Since v2.39 libmount prefers "struct libmnt_optlist" to keep mount options
rather than the original "struct libmnt_fs". This is problem if the
"fs" struct is defined and maintained outside the context.
The library has already a way how to sync "fs" and "optlist", but this
needs to be improved and used more widely. Changes:
* force "fs" from context to always read options from "optlist"
* copy options from "fs" to "optlist" in mnt_context_set_fs()
* internally redirect mnt_fs_* API for options to "optlist" if optlist
defined
* add simple test to make sure options from different sources are
always merged together
Addresses: https://github.com/util-linux/util-linux/issues/2326 Signed-off-by: Karel Zak <kzak@redhat.com>
Frantisek Sumsal [Thu, 22 Jun 2023 10:33:12 +0000 (12:33 +0200)]
ci: cancel running jobs on push
Let's cancel already running GH Actions jobs when a PR is (force) pushed
to conserve resources and make the CI runs faster thanks to the freed up
queue.
Frantisek Sumsal [Tue, 20 Jun 2023 21:01:35 +0000 (23:01 +0200)]
ci: collect coverage on _exit() as well
_exit() skips the gcov hooks, so we lose all coverage collected up to
that point. Let's work around this by intercepting _exit() with our
wrapper that calls __gcov_dump() just before _exit().
Rasmus Villemoes [Tue, 13 Jun 2023 10:14:28 +0000 (12:14 +0200)]
hwclock: add support for RTC_VL_READ/RTC_VL_CLR ioctls
Implement a way for userspace to query the status of the backup
battery, if supported by the hardware and driver.
The RTC_VL_* bits are a somewhat recent addition (3431ca4837bf, but
really only from b0efe0281234) to the uapi header,
so provide our own definition if the build host's header doesn't.
Masatake YAMATO [Thu, 22 Jun 2023 02:28:47 +0000 (11:28 +0900)]
lsfd: (filter) weakly support ARRAY_STRING and ARRAY_NUMBER json types
We will have operators for array types in the future. Till having
them, we treat the types as STRING. So we can use string operators for
the column having types.
Masatake YAMATO [Fri, 9 Jun 2023 12:35:55 +0000 (21:35 +0900)]
lsfd: introduce XMODE column, extensible variant of MODE
The original MODE column comes from three letters (rwx) may not be
enough for representing various aspects of file descriptors and memory
mappings. We want to add more items in the future.
However, the description of MODE in lsfd(1) doesn't wrote about its
extensibility. Adding more letters to the column can break
compatibility in someone's use case.
This change introduces XMODE column. Unlike MODE, XMODE is declared as
an extensible column in lsfd(1). Currently, it shows the same items as
the MODE column does.