Karel Zak [Thu, 26 Sep 2024 12:44:36 +0000 (14:44 +0200)]
libmount: support bind symlink over symlink
The new mount API allows for the use of AT_SYMLINK_NOFOLLOW when
opening a mount tree (aka the "mount source" for libmount).
As a result, you can now replace one symlink with another by using a
bind mount.
By default, the mount(8) command follows symlinks and canonicalizes
all paths. However, with the X-mount.nocanonicalize=source option, it
is possible to open the symlink itself. Similarly, with the
X-mount.nocanonicalize=target option, the path of the mount point can
be kept as the original symlink. (Using X-mount.nocanonicalize without
any argument works for both the "source" and "target".)
Example:
# file /mnt/test/symlinkA /mnt/test/symlinkB
/mnt/test/symlinkA: symbolic link to /mnt/test/fileA
/mnt/test/symlinkB: symbolic link to /mnt/test/fileB
The result is that 'symlinkB' is still a symlink, but it now points to
a different file.
This commit also modifies umount(8) because it does not work with
symlinks by default. The solution is to call umount2(UMOUNT_NOFOLLOW)
for symlinks after a failed regular umount(). For example:
The new kernel mount API can bind-mount over a symlink. However, this
feature does not work with libmount because it canonicalizes all paths
by default. A possible workaround is to use the --no-canonicalize
option on the mount(8) command line, but this is a heavy-handed
solution as it disables all conversions for all paths and tags (such
as LABEL=) and fstab processing.
This commit introduces the X-mount.nocanonicalize userspace mount
option to control canonicalization. It only affects paths used for
mounting and does not affect tags and searching in fstab. Additionally,
this setting possible to use in fstab.
If the optional argument [=source|target] is not specified, then paths
canonicalization is disabled for both the source and target paths.
Adresses: https://github.com/util-linux/util-linux/issues/2370 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 24 Sep 2024 10:31:39 +0000 (12:31 +0200)]
Merge branch 'sock-netns' of https://github.com/0x7f454c46/util-linux
* 'sock-netns' of https://github.com/0x7f454c46/util-linux:
lsns: List network namespaces that are held by a socket
lsfd: Gather information on target socket's net namespace
nsenter: Provide an option to join target process's socket net namespace
Michal Suchanek [Tue, 24 Sep 2024 07:19:39 +0000 (09:19 +0200)]
partx: Fix example in man page
The example is:
partx -d --nr :-1 /dev/sdd
Removes the last partition on _/dev/sdd_.
The documentation says:
M:
Specifies the lower limit only (e.g. --nr 2:).
:N
Specifies the upper limit only (e.g. --nr :4).
In the above example the lower limit is not set and the upper is set to
the last partition, meaning all partitions. The lower limit should be
set instead.
nsenter: Provide an option to join target process's socket net namespace
The network namespace of a socket can be different from the target
process. Previously there were some userspace issues where a
net-namespace was held alive by a socket leak. For this purpose Arista's
linux kernel has a patch to provide socket => netns map by procfs pid/fd
directory links.
Add nsenter option to join the network namespace of a target process'
socket.
Karel Zak [Mon, 16 Sep 2024 12:50:43 +0000 (14:50 +0200)]
sfdisk: add --discard-free
Why do we need this? It can be difficult for end-users to discard
unpartitioned areas using blkdiscard, as it requires using fdisk to
obtain a list of free areas and then using blkdiscard with the correct
--offset and --length options. It is less risky for end-users to use
(s)fdisk, as they have a better understanding of the disk layout.
Addresses: https://github.com/util-linux/util-linux/issues/2804 Signed-off-by: Karel Zak <kzak@redhat.com>
Yao Zi [Mon, 9 Sep 2024 18:08:30 +0000 (18:08 +0000)]
bash-completion: look: rewrite completion logic
look(1) opens /usr/share/dict/words as dictionary by default. Doing TAB
completion for look(1) without the dictionary installed will result in
popups like
$ look look: /usr/share/dict/words: No such file or directory
messing up the terminal.
As /usr/share/dict/words is not shipped by quite a few distros nowadays
and it should not be listed as a hard dependency of util-linux, we make
sure the dictionary exists before calling look(1) when doing completion,
avoiding these error messages.
When completing the word without anything specified on the command line,
alphabets and numbers instead of all words are listed as a hint, for
better interacting experience.
Karel Zak [Thu, 5 Sep 2024 08:18:38 +0000 (10:18 +0200)]
Merge branch 'PR/env-whitelist' of github.com:karelzak/util-linux-work
* 'PR/env-whitelist' of github.com:karelzak/util-linux-work:
login: add LOGIN_ENV_SAFELIST /etc/login.def item
su: use lib/env.c for --whitelist-environment
env: add env_list_add_getenv() and env_list_add_getenvs()
autotools: improve devel-non-docs config-gen scenario
env: cleanup env_list API
env: add "overwrite" argument to env_list_setenv()
env: save parsed variables into ul_env_list
tests: add su --whitelist-environment test
Jan Engelhardt [Fri, 30 Aug 2024 20:44:56 +0000 (20:44 +0000)]
lscpu: add procfs–sysfs dump from Milk-V Pioneer
already in tree:
rv64-linux: just a BeagleV Starlight SBC (no longer in production)
rv64-visionfive2 is interesting because it's a system with an odd CPU count / mix of core types (4+1)
new dump:
rv64-milkvpioneer is interesting because it's arguably a server board, i.e. with a whole bunch of cores and NUMA nodes.
Karel Zak [Wed, 28 Aug 2024 10:10:50 +0000 (12:10 +0200)]
login: add LOGIN_ENV_SAFELIST /etc/login.def item
It is possible to preserve the entire environment (-p), but it is
rarely a good idea. The new configuration file item allows for
specifying a list of variables to protect, such as locale-related
environment variables.
Addresses: https://github.com/util-linux/util-linux/pull/3159 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 28 Aug 2024 09:23:31 +0000 (11:23 +0200)]
env: add env_list_add_getenv() and env_list_add_getenvs()
* Add env_list_add_getenv() to import a single variable from the
environ[] array. The function may accept a default value if getenv()
does not return anything.
* Add env_list_add_getenvs() to import multiple variables from the
environ[] array.
Karel Zak [Tue, 27 Aug 2024 11:07:56 +0000 (13:07 +0200)]
env: save parsed variables into ul_env_list
The struct ul_env_list is currently only used to store the value of
env when sanitizing environ[]. It would be beneficial to also use the
functions related to ul_env_list for other purposes. In order to do
this, it is important to keep the NAME and VALUE components separate.
* Accept non-terminated name and value for env_list_add().
* Add env_list_add_from_string() to add item to the list from a
"name=value" string.
* Add env_list_add_variable() to add item to the list using separate
"name" and "value" strings.
* Update __sanitize_env() to use env_list_add_from_string().
* Modify the test to use "abc" as the value instead of copying the
variable name (with '=') to the value.
Karel Zak [Mon, 2 Sep 2024 12:21:40 +0000 (14:21 +0200)]
libfdisk: check alignment reset return codes
Traditionally, there was only recalculation based on disk properties.
However, since libfdisk now supports additional script headers to
modify the default alignment, we need to check return codes. This is
because users can specify nonsensical values. If we ignore the return
codes, the library will report the issue multiple times and
return an error to the application when creating a new disk label.
Old version:
>>> Script header accepted.
>>> Last LBA specified by script is out of range.
Last LBA specified by script is out of range.
Last LBA specified by script is out of range.
Failed to apply script headers, disk label not created: Numerical result out of range
Fixed version:
>>> Script header accepted.
>>> Last LBA specified by script is out of range.
Failed to apply script headers, disk label not created: Numerical result out of range.
Karel Zak [Mon, 2 Sep 2024 12:04:18 +0000 (14:04 +0200)]
sfdisk: ignore last-lba from script on --force
The last LBA depends on the disk size. It seems like a good idea to
ignore it when using the --force option, in order to make it possible
to apply the script on smaller disks.
Addresses: https://github.com/util-linux/util-linux/issues/3186 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 29 Aug 2024 09:52:31 +0000 (11:52 +0200)]
Merge branch 'PR/buildsys-lsfd-bpf' of github.com:karelzak/util-linux-work
* 'PR/buildsys-lsfd-bpf' of github.com:karelzak/util-linux-work:
meson: check for BPF_OBJ_NAME_LEN and linux/bpf.h
autotools: Check for BPF_OBJ_NAME_LEN (required by lsfd)
Gábor Németh [Thu, 29 Aug 2024 06:59:23 +0000 (08:59 +0200)]
Optionally execute a program after group change
We accept a `-c` command option or possible second argument which is then
invoked through the user's shell after the group change, as by the `sg`
utility. The default is still running the shell itself.
Guixin Liu [Wed, 21 Aug 2024 08:49:54 +0000 (16:49 +0800)]
lscpu: optimize query virt pci device
The lscpu command needs to traverse the /proc/bus/pci/devices file
three times to check for any PCI devices related to virtualization.
If there are many PCI devices on the machine, this can lead to
increased execution time for lscpu. It would be beneficial to
consolidate these queries into a single check to optimize the
execution time of lscpu.
Use time command to test on a machine with 13000 PCI devices:
before:
real 0m13.506s
user 0m0.028s
sys 0m13.409s
after:
real 0m5.834s
user 0m0.018s
sys 0m5.771s
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
Karel Zak [Thu, 22 Aug 2024 09:31:21 +0000 (11:31 +0200)]
Merge branch 'findmnt-Q' of https://github.com/masatake/util-linux
* 'findmnt-Q' of https://github.com/masatake/util-linux:
tests: (findmnt) add a case testing -Q option
findmnt: (man) write about -Q,--filter option
findmnt: add -Q,--filter option
findmnt: (refactor) convert add_column macro to a function
findmnt: (refactor) add a helper function making an instance of libscols_table
findmnt: (refactor) remove global variables shared between findmnt.c and fintmnt-verify.c
Karel Zak [Thu, 22 Aug 2024 06:56:52 +0000 (08:56 +0200)]
more: make sure we have data on stderr
more(1) uses more_poll() to monitor data on stdin, stderr, and
signals. It is used before read_command(), but this function only
reads from stderr. Therefore, if any other non-stderr event occurs,
this function will wait on read(). In this case, more(1) will not
react to signals anymore. We need to ensure that more(1) only waits in
more_poll().
Try
for x in {1..1000}; do echo "line $x"; done | more
to reproduce.
Reported-by: Radka Skvarilova <rskvaril@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Dmitry V. Levin [Sun, 11 Aug 2024 08:00:00 +0000 (08:00 +0000)]
meson: use a / b instead of join_paths(a, b)
According to [1], since meson 0.49.0, using the / operator on strings
is equivalent to calling join_paths().
As the expressions written using the / operator are shorter and nicer
than their equivalents written using join_paths(), and given that
we've been using this new operator since commit 5f2c862a4aff19f5bc732e677405f04e2d07c211, let's convert remaining
join_paths() invocations to use the / operator instead.