Karel Zak [Tue, 1 Oct 2024 11:56:52 +0000 (13:56 +0200)]
Merge branch 'test_mkfds-dont-free-and-close-when-exit-with-error' of https://github.com/masatake/util-linux
* 'test_mkfds-dont-free-and-close-when-exit-with-error' of https://github.com/masatake/util-linux:
tests: (test_mkfds) don't close fds and free memory objects when exiting with EXIT_FAILURE
tests: (test_mkfds,refactor) simplify nested if conditions
tests: (test_mkfds) save errno before calling system calls for clean-up
tests: (test_mkfds, cosmetic) add an empty line before the definition of struct sysvshm_data
Thomas Weißschuh [Wed, 25 Sep 2024 06:12:45 +0000 (08:12 +0200)]
login-utils/su-common: Validate all return values again
The additional coded added in commit d6564701e812 ("login-utils/su-common: Check that the user didn't change during PAM transaction")
was inserted in between the assignment and tests of "rc",
making the return value unchecked.
Add a new explicit check.
Thomas Weißschuh [Wed, 25 Sep 2024 06:09:29 +0000 (08:09 +0200)]
meson: test for pidfd_getfd()
Commit 55c7120accab ("nsenter: Provide an option to join target process's socket net namespace")
added stubs for pidfd_getfd() but didn't add the code for meson to check
if the function is already available.
Karel Zak [Tue, 24 Sep 2024 11:37:13 +0000 (13:37 +0200)]
libfdisk: (dos) ignore incomplete EBR for non-wholedisk
The logical partitions are defined by a chain of extended partitions,
with the beginning of the chain located on the whole disk device.
If a user runs "fdisk --list /dev/sda4", libfdisk cannot calculate proper
offsets for the items in the chain, resulting in the following error
message:
Failed to read extended partition table (offset=22528): Invalid argument
This error message may confuse users and is unnecessary when fdisk is
used in list-only mode (--list option). It would be sufficient to only
print the content of the partition without the error message and not
continue to the next item in the chain.
However, in write mode (without --list), the error message will still
be displayed as it is potentially dangerous to edit the EBR table.
Addresses: https://issues.redhat.com/browse/RHEL-59867 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.
login-utils/su-common: Check that the user didn't change during PAM transaction
PAM modules can change the user during their execution, in such case su
would still use the user that has been provided giving potentially
access to another user with the credentials of another one.
So prevent this to happen, by ensuring that the final PAM user is
matching the one required
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>