Markus Mayer [Tue, 1 Aug 2023 19:59:27 +0000 (12:59 -0700)]
libmount: check for struct statx
Let's ensure struct statx exists before we try to use it. Checking for
the existence of linux/stat.h is not sufficient. This is because
[uapi/]linux/stat.h has existed since Linux 3.7, however struct statx
was only introduced with Linux 4.11.
The problem arises if one happens ot be using kernel headers from within
the aforementioned range, such as Linux 4.9.
CC libmount/src/la-utils.lo
In file included from libmount/src/utils.c:31:
./include/fileutils.h:100:33: warning: declaration of 'struct statx' will not
be visible outside of this function [-Wvisibility]
unsigned int mask, struct statx *stx)
^
libmount/src/utils.c:117:16: error: variable has incomplete type 'struct statx'
struct statx stx = { 0 };
^
libmount/src/utils.c:117:10: note: forward declaration of 'struct statx'
struct statx stx = { 0 };
^
libmount/src/utils.c:125:5: error: use of undeclared identifier 'STATX_TYPE'
STATX_TYPE
^
libmount/src/utils.c:126:8: error: use of undeclared identifier 'STATX_MODE'
| STATX_MODE
^
libmount/src/utils.c:127:8: error: use of undeclared identifier 'STATX_INO'
| STATX_INO,
^
1 warning and 4 errors generated.
make[4]: *** [Makefile:11269: libmount/src/la-utils.lo] Error 1
Checking for the presence of struct statx explicitly avoids this
problem.
Markus Mayer [Tue, 1 Aug 2023 19:59:26 +0000 (12:59 -0700)]
libmount: check for linux/mount.h
Check that linux/mount.h is present before using features that rely on
it.
It is necessary to check for the presence of linux/mount.h explicitly.
Simply relying on the presence of several syscalls (e.g. SYS_move_mount,
SYS_open_tree) does not work reliably, at least not in a cross-compiling
environment.
The syscall definitions are provided by the C library. Meanwhile,
linux/mount.h is provided by the kernel. This opens the possibility for
discrepancies.
A problem arises if the C library (e.g. musl-1.2.3) defines all "mount
fd API" syscalls (and HAVE_MOUNTFD_API becomes true), but the kernel
headers are old enough to not provide linux/mount.h. The resulting error
looks as follows. This example is using an LLVM-13 cross-compiler from
x86_64 to aarch64 with musl-1.2.3 as the C library.
CC libmount/src/la-hooks.lo
In file included from libmount/src/hooks.c:30:
./include/mount-api-utils.h:11:10: fatal error: 'linux/mount.h' file not found
^~~~~~~~~~~~~~~
1 error generated.
make[4]: *** [Makefile:11185: libmount/src/la-hooks.lo] Error 1
To prevent this condition, we add a check to configure that will test
for the presence of linux/mount.h in addition to testing for the mount
fd API. Only if both conditions are met can we actually use the mount
fd API.
If the systemcall is not available ENOSYS is returned.
Under glibc the statx implementation also has its own fallback logic.
As AT_STATX_DONT_SYNC can't be implemented correctly in that fallback
logic the wrapper will return EINVAL in case the emulation is needed and
AT_STATX_DONT_SYNC is set.
So also use our own fallback in that case.
Fixes: #2409 Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Karel Zak [Wed, 2 Aug 2023 10:57:37 +0000 (12:57 +0200)]
column: fix -l
The original implementation is complicated and broken.
It's possible to calculate the rest of the string (for the last
column) from the current position rather than calculate it
continuously. Use the last wcstok() result also means that it will
work as expected independently on "greedy" mode (skips repeating
separators.
# printf 'a b c d\n1 2 3 4\n' | ./column -t -o '|' -l3
a|b|c d
1|2|3 4
Karel Zak [Tue, 1 Aug 2023 12:49:48 +0000 (14:49 +0200)]
libmount: cleanup --fake mode
It was originally designed to play nasty games with /etc/mtab (mount
when /etc is read-only and update later when it's write-able).
The --fake is completely useless with the new API due to complexity
where we cannot skip any step, because the next stuff depends on it.
So, it makes more sense skip all functionality where libmount does
anything significant.
This commit add --fake check to hooks logic to skip all hooks as the
hooks are place where libmount implements mount related invasive
operations (create mountpoint, namespaces, create superblock, move,
mount, etc.).
Frankly, --fake without mtab is useless.
Fixes: https://github.com/util-linux/util-linux/issues/2395 Signed-off-by: Karel Zak <kzak@redhat.com>
tests: (lsfd::option-inet) get child-processes' pids via fifo
Close #2399.
The original code assumes the background processes prepare sockets enough
fast. #2399 showed the assumption was wrong; lsfd reported half-cooked
sockets.
To avoid the timing issue, the test case with this change uses a fifo
to receive pids from the child test_mkfds processes. test_mkfds reports
its pid after cooking the sockets. When the option-inet script recives the pid,
we can expect the sockets are ready.
Note: bash's coproc cannot be used here; it supports only one co-process at
once.
Analysed-by: Alexander Kanavin <alex.kanavin@gmail.com> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Karel Zak [Mon, 31 Jul 2023 10:29:01 +0000 (12:29 +0200)]
Merge branch 'lsfd--handle-newline-in-unix-socket-path' of https://github.com/masatake/util-linux
* 'lsfd--handle-newline-in-unix-socket-path' of https://github.com/masatake/util-linux:
lsfd: (test) add a case for testing a unix socket including newline characters in its path name
lsfd: re-fill unix socket paths with sockdiag netlink interface
lsfd: add comment listing functions names importing via #include
lsfd: include common headers in lsfd.h
lsfd: include system header files first
lsfd: fix a misleading parameter name
lsfd: add const modifier
Karel Zak [Mon, 31 Jul 2023 10:13:24 +0000 (12:13 +0200)]
Merge branch 'lsfd--bpf-prog' of https://github.com/masatake/util-linux
* 'lsfd--bpf-prog' of https://github.com/masatake/util-linux:
test: (lsfd) add a case for testing BPF-PROG.TYPE and BPF-PROG.TYPE.RAW columns
test: (mkfds::bpf-prog) new factory
lsfd: add BPF-PROG.TYPE, BPF-PROG.TYPE.RAW, and BPF-PROG.ID columns
The fincore tests call ts_log_both inside an output redirection of both stdout
and stderr, leading to the ts_log_both output ending up twice in both stdout
and stderr.
Call ts_log_both before setting up the output redirection.
Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
Thomas Weißschuh [Wed, 26 Jul 2023 14:32:59 +0000 (16:32 +0200)]
chrt: (tests) increase deadline test parameters
Since kernel commit b4098bfc5efb ("sched/deadline: Impose global limits on sched_attr::sched_period")
the value for dl_period has a lower bound of 100us.
Adjust the test parameters so the test can work on newer kernels.
Unlike the original work, this commit keeps /proc related code.
Unlike /proc interface, the sockdiag information source doesn't provide
enough information for filling struct unix_xinfo::st member. So this
commit uses /proc interface for filling the most of all unix_xinfo
members as before.
On the other hande, as discussed in
https://github.com/util-linux/util-linux/pull/2067, the /proc
interface in unreliable if a unix path name includes newline
characters. This commit uses the sockdiag interface to compensate
for the weakness of the /proc interface.
Karel Zak [Thu, 16 Mar 2023 12:41:36 +0000 (13:41 +0100)]
losetup: add --loop-ref and REF column
The lo_file_name is nowhere used (kernel uses backing file descriptor,
no path) and it was used to store limited info about the backing file path
(64 bytes only!). For backward compatibility, we still fill lo_file_name
with the path, but it's nowhere in the userspace used as the complete
backing file path in sysfs.
This commit introduces a new option to overwrite the default path in
lo_file_name. The idea is to use the reference string by udevd in
/dev/loop/by-ref to address loop devices independently on paths.
Addresses: https://github.com/util-linux/util-linux/issues/2106 Suggested-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 20 Jul 2023 10:34:14 +0000 (12:34 +0200)]
libmount: use some MS_* flags as superblock flags
The old mount(2) API usually utilizes MS_* flags to set up the VFS
node. However, there are some exceptions like "sync" (MS_SYNCHRONOUS),
where the flag is used (by kernel) for the superblock instead. The new
API addresses this issue, ensuring that these options are used for
fsconfig().
This commit introduces MNT_SUPERBLOCK to identify these options in the
libmount options Linux map, and it enforces the new mount code to
utilize these options for fsconfig(FSCONFIG_SET_FLAG).
Reported-by: Abbink Esger <esger.abbink.ext@siemens.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 18 Jul 2023 08:05:03 +0000 (10:05 +0200)]
Merge branch 'wip/rishi/libmount-handle-failure-to-apply-flags-as-part-of-mount' of https://github.com/debarshiray/util-linux
* 'wip/rishi/libmount-handle-failure-to-apply-flags-as-part-of-mount' of https://github.com/debarshiray/util-linux:
libmount: handle failure to apply flags as part of a mount operation
Karel Zak [Tue, 18 Jul 2023 08:03:35 +0000 (10:03 +0200)]
Merge branch 'lsfd--revise-help-message' of https://github.com/masatake/util-linux
* 'lsfd--revise-help-message' of https://github.com/masatake/util-linux:
lsfd: show default columns in the help message
lsfd: update the help message for XMODE column
lsfd: introduce -H, --list-columns option for making help messages short
lsfd: (man) fix the form for the optional argument of --inet option
lsfd: rearrange the aligment of the help messages
lsfd: use the specified output stream for printing help messages
Karel Zak [Tue, 18 Jul 2023 08:01:02 +0000 (10:01 +0200)]
Merge branch 'lsclocks/dynamic-clock' of https://github.com/t-8ch/util-linux
* 'lsclocks/dynamic-clock' of https://github.com/t-8ch/util-linux:
lsclocks: automatically discover dynamic clocks
lsclocks: add support for dynamic clocks
lsclocks: split out data function
lsclocks: add COL_TYPE
Karel Zak [Mon, 17 Jul 2023 12:15:33 +0000 (14:15 +0200)]
swapon: (man) fix --priority description
It's not true anymore that Linux uses -1 as the default. I could be
also another negative number (default is -2 for the first swap since
kernel commit a2468cc9bfdff6139f59ca896671e5819ff5f94a).
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2188894 Signed-off-by: Karel Zak <kzak@redhat.com>
Debarshi Ray [Thu, 13 Jul 2023 09:07:27 +0000 (11:07 +0200)]
libmount: handle failure to apply flags as part of a mount operation
If a mount operation with extra flags runs into an EPERM when applying
the flags, then mnt_context_get_mount_excode() returns 'Unknown error
5005' and MNT_EX_FAIL. Here's an example:
Create a mount point on the host with 'nodev,nosuid,noexec':
$ dd if=/dev/zero of=/var/tmp/loopfile bs=40960 count=1024
$ sudo losetup --find /var/tmp/loopfile
$ sudo mkfs.ext4 /dev/loop0
$ sudo mkdir /mnt/a
$ sudo mount -o nosuid,nodev,noexec /dev/loop0 /mnt/a
Check the mount options to be sure:
$ findmnt --output OPTIONS,PROPAGATION /mnt/a
OPTIONS PROPAGATION
rw,nosuid,nodev,noexec,relatime,seclabel shared
Enter a mount and user namespace:
$ podman run \
--interactive \
--privileged \
--rm \
--tty \
--volume /:/run/host:rslave \
registry.fedoraproject.org/fedora:38 \
/bin/bash
Try to bind mount the mount point from the host inside the namespace
with some extra flags:
# mkdir ~/b
# mount --bind -o ro /run/host/mnt/a ~/b
mount: /root/b: filesystem was mounted, but any subsequent operation
failed: Unknown error 5005.
# echo $?
32
It will be better to show something more human-readable than 'Unknown
error 5005'.
Secondly, an exit code of 32 means 'mount failure', which isn't quite
correct here. The mount operation is split into two mount(2) calls,
where the first one uses MS_BIND to create the bind mount, and the
second uses MS_REMOUNT | MS_BIND | MS_RDONLY to apply the 'ro' flag.
Here, the first mount(2) does succeed:
# findmnt --output OPTIONS,PROPAGATION ~/b
OPTIONS PROPAGATION
rw,nosuid,nodev,noexec,relatime,seclabel private,slave
It's only the application of the 'ro' flag with the second mount(2) that
fails with an EPERM. Hence, an exit code of 1 that means 'incorrect
invocation or permissions' seems more appropriate.
Signed-off-by: Debarshi Ray <rishi@fedoraproject.org>
mdadm superblocks before 1.1 are placed at the end of the device, which
means that the data contained inside the array starts at offset 0. For
LUKS inside MD, blkid falsely detects this as plain LUKS instead of a
linux_raid_member. This causes e.g. dracut to not assemble the array
during boot and system startup fails.
Karel Zak [Tue, 11 Jul 2023 10:01:00 +0000 (12:01 +0200)]
Merge branch 'lsfd--multiplexed-flag-of-XMODE-column' of https://github.com/masatake/util-linux
* 'lsfd--multiplexed-flag-of-XMODE-column' of https://github.com/masatake/util-linux:
tests: (lsfd) add a case testing 'm' flag in XMODE column
lsfd: add 'm' flag representing "multiplexed by epoll_wait(2)" to XMODE column
lsfd: (man) fix the broken page output for the description of NAME column
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.