Karel Zak [Wed, 27 Mar 2024 10:46:01 +0000 (11:46 +0100)]
Merge branch 'blkid/json' of https://github.com/t-8ch/util-linux
* 'blkid/json' of https://github.com/t-8ch/util-linux:
blkid: add json output format
blkid: (tests) test output formats
blkid: (tests) use correct blkid binary
Karel Zak [Tue, 26 Mar 2024 11:45:24 +0000 (12:45 +0100)]
lsipc: fix semaphore USED counter
The code incorrectly counts only with the first item in the linked
list (due to a typo). It seems rather fragile to use "semds" and
"semdsp" as variable names in the same code ...
# lsipc -gs
Old:
KEY ID PERMS OWNER NSEMS RESOURCE DESCRIPTION LIMIT USED USE%
SEMMNI Number of semaphore identifiers 32000 3 0.01%
SEMMNS Total number of semaphores 1024000000 369 0.00%
SEMMSL Max semaphores per semaphore set. 32000 - -
SEMOPM Max number of operations per semop(2) 500 - -
SEMVMX Semaphore max value 32767 - -
Fixed:
KEY ID PERMS OWNER NSEMS RESOURCE DESCRIPTION LIMIT USED USE%
SEMMNI Number of semaphore identifiers 32000 3 0.01%
SEMMNS Total number of semaphores 1024000000 156 0.00%
SEMMSL Max semaphores per semaphore set. 32000 - -
SEMOPM Max number of operations per semop(2) 500 - -
SEMVMX Semaphore max value 32767 - -
Addresses: https://issues.redhat.com/browse/RHEL-30269 Signed-off-by: Karel Zak <kzak@redhat.com>
Tim Hallmann [Sun, 24 Mar 2024 19:14:30 +0000 (20:14 +0100)]
rev: Check for wchar conversion errors
Commit c9cc84621ca98ef85499e83ca56f05f12055f193 introduced a regression
where only the actual EOF is handled, not other error conditions
returning WEOF. This leads to an infinite loop upon encountering
conversion errors. For example (using LC_CTYPE="en_US.UTF-8"):
Jordan Williams [Wed, 20 Mar 2024 16:41:49 +0000 (11:41 -0500)]
meson: Only build blkzone and blkpr if the required linux header exists
Checks for the required headers for blkzone and blkptr are done for
Autotools.
This logic wasn't carried over to Meson.
This PR just adds the same checks.
Fixes #2850.
Signed-off-by: Jordan Williams <jordan@jwillikers.com>
The blamed commit converted script to use the generic pty code that
was added by commit 6954895cae34 ("lib/pty-session: add generic PTY
container code").
Commit ec10634e7ec4 says the new pty stuff is based on script.
However, there is difference in signal handling.
Before the commit, only the signals that the script was interested
in were blocked and handled by signalfd.
After the commit, all signals are blocked and only the interested
signals are handled.
This causes regression in the following scenario:
1. run `script` via /etc/profile.d for ssh session
2. login to a ssh session using bash
3. run `sudo -i`
4. wait until ssh session timeout
Karel Zak [Tue, 5 Mar 2024 09:14:08 +0000 (10:14 +0100)]
Merge branch 'blockdev' of https://github.com/EvgeniyRogov/util-linux
* 'blockdev' of https://github.com/EvgeniyRogov/util-linux:
- Fixed report error code in blockdev. - Minor: Added a period at the end of "--rereadpt" description.
Karel Zak [Mon, 4 Mar 2024 11:38:35 +0000 (12:38 +0100)]
Merge branch 'lsfd--github-issue-2819' of https://github.com/masatake/util-linux
* 'lsfd--github-issue-2819' of https://github.com/masatake/util-linux:
tests: (lsfd::mkfds-inotify) consider environments not having / as a mount point
Stanislav Brabec [Wed, 28 Feb 2024 14:06:14 +0000 (15:06 +0100)]
setterm: Document behavior of redirection
Debugging an error of setterm, I realized that setterm --powerdown operates
on stdout but setterm --powersave operates on stdin. Such unexpected
behavior should be documented.
I prefer a less accurate generic "always redirect both stdin and stdout"
over recommending of the correct I/O stream for each option separately.
Karel Zak [Thu, 29 Feb 2024 08:50:59 +0000 (09:50 +0100)]
Merge branch 'lsfd--btrfs' of https://github.com/masatake/util-linux
* 'lsfd--btrfs' of https://github.com/masatake/util-linux:
tests: (lsfd::mkfds-inotify-btrfs) test INOTIFY.INODES cooked output
lsfd: extend nodev table to decode "btrfs" on SOURCE column
lsfd: (refactor) rename a member of struct proc
lsfd: (refactor) rename a local variable and a parameter
lsfd: (refactor) split the function processing mountinfo file
lsfd: (refactor) store a mnt_namespace object to struct process
lsfd: (refactor) use a binary tree as the implementation for mnt_namespaces
lsfd: read /proc/$pid/ns/mnt earlier
lsfd: (refactor) rename add_nodevs to read_mountinfo
lsfd: make the way to read /proc/$pid/mountinfo robust
lsfd: (cosmetic) normalize whitespaces
Karel Zak [Tue, 27 Feb 2024 17:38:02 +0000 (18:38 +0100)]
hexdump: check blocksize when display data
hexdump(1) stores input to buffer and apply format unit when prints
the output. The unit can move pointer which points to the buffer, but
code does not check for limits.
Fixes: https://github.com/util-linux/util-linux/issues/2806 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 26 Feb 2024 11:44:10 +0000 (12:44 +0100)]
libmount: report kernel message from new API
This is a very minimalistic implementation for v2.40 designed to print
error messages from the kernel. It exclusively displays errors, and
the patch does not introduce any new library interface for this
purpose. Instead, it simply replaces hardcoded messages within
libmount with kernel messages.
It's worth noting that the final implementation will necessitate
per-hook error handling in libmount and likely a new library API to
access other types of messages (warnings, notices, etc.).
Jan Kara [Wed, 21 Feb 2024 17:30:50 +0000 (18:30 +0100)]
libmount: don't hold write fd to mounted device
Avoid holding writeable fd to a loop device that is being mounted. In
the hardened configurations (CONFIG_BLK_DEV_WRITE_MOUNTED = n) the
kernel wants to make sure nobody else has the block device writeably
open when mounting so this makes the mount fail.
Reported-by: JunChao Sun <sunjunchao2870@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Acked-by: Christian Brauner <brauner@kernel.org>
Masatake YAMATO [Fri, 5 Jan 2024 05:31:46 +0000 (14:31 +0900)]
lsfd: extend nodev table to decode "btrfs" on SOURCE column
When filling SOURCE column, lsfd decodes the name of the device where the
file object is. If the file object is sourced from a file system, lsfd
fills the column with the file system's name.
As #2349 and #2308, if the file system is btrfs, lsfd couldn't decode
the name correctly. This change and its preceding changes fix this bug.
"devnum offset" causes the trouble. On btrfs, the device number
reported by stat syscall and proc fs are different.
For the details of "devnum offset", see "Mechanism behind the
devnum offset". About the way to fix it, see "How to adjust the output of lsfd".
Without this change:
$ ./lsfd -Q '(ASSOC == "exe")' -p $$
COMMAND PID USER ASSOC XMODE TYPE SOURCE MNTID INODE NAME
zsh 19318 yamato exe ------ REG 0:38 0 589767 /usr/bin/zsh
With this change:
$ ./lsfd -Q '(ASSOC == "exe")' -p $$
COMMAND PID USER ASSOC XMODE TYPE SOURCE MNTID INODE NAME
zsh 19318 yamato exe ------ REG btrfs 0 589767 /usr/bin/zsh
Mechanisum behind the devnum offset
-----------------------------------
Both stat command and the inotify field in fdinfo refer to an inode.
filename_lookup(https://elixir.bootlin.com/linux/v6.2.9/source/fs/namei.c#L2495)
is the function getting the inode for a given file
name. filename_lookup returns a struct path. Via path->detnry->inode,
the caller of filename_lookup can get the inode.
stat command calls statx system call. statx calls filename_lookup
eventually.
inotify_add_watch system call takes a file name. The inotify_add_watch
calls the filename_lookup eventually for getting the inode for the
file name. The inode number that inotify_add_watch gets via
filename_lookup is printed in the inotify field in fdinfo.
The device number, the subject of this issue, can be obtained via
path->detnry->inode->i_sb->s_dev. Both the stat command and the
inotify field in fdinfo use the filename_lookup for getting path. If
they use the same function, why don't the device numbers match? I
monitored the device numbers obtained via
path->detnry->inode->i_sb->s_dev by inserting a systemtap probe to
filename_lookup. I saw the numbers matched.
However, the number monitored via systemtap did not match the number
printed by the stat command. statx system call doesn't use
path->detnry->inode->i_sb->s_dev , the value obtained via
filename_lookup, directly. statx calls vfs_statx. vfs_statx calls
vfs_getattr after calling the filename_lookup for filling struct
kstat. vfs_getattr calls inode->i_op->getattr, a file system specific
method for filling struct kstat if it is available. btrfs has an
implementation for the method,
btrfs_getattr(https://elixir.bootlin.com/linux/v6.2.9/source/fs/btrfs/inode.c#L9007):
stat->dev = BTRFS_I(inode)->root->anon_dev;
The dev member is overwritten with btrfs specific value.
How to adjust the output of lsfd
--------------------------------
lsfd already reads mountinfo files.
1. Get the "rawnum" and mount point
The device numbers in a mountinfo file are raw; btrfs is not
considered. Let's call the number "rawnum" here. When reading the
mountinfo file, lsfd can know the mount points of btrfs.
By calling "stat" system call for the mount point getting in the
step 1, lsdf can know the device number the btrfs customizes with
its getattr method. Let's call the device number "cookednum".
Karel Zak [Thu, 22 Feb 2024 09:26:15 +0000 (10:26 +0100)]
Merge branch 'enosys/dump' of https://github.com/t-8ch/util-linux
* 'enosys/dump' of https://github.com/t-8ch/util-linux:
setpriv: (tests) add seccomp test
setpriv: add support for seccomp filters
enosys: add functionality to dump filter
include: introduce seccomp.h
Karel Zak [Wed, 21 Feb 2024 09:13:50 +0000 (10:13 +0100)]
docs: cleanup public domain license texts
The absence of an official 'Public domain' definition is the reason
why, for example, the Fedora distribution aggregates all variants from
various projects to make them reviewable.
This commit unifies the 'Public domain' statements to make it simple.
Karel Zak [Tue, 20 Feb 2024 11:26:33 +0000 (12:26 +0100)]
more: fix poll() use
The more(1) command utilizes signalfd() to monitor signals and reads
commands from the user via stderr (as stdin is typically used for
piping and not for user interaction).
However, the current more_poll() implementation ignores stderr. As a result,
more(1) waits on read(stderr) while completely ignoring signals. This issue
becomes evident when using commands like:
grep foo /path/file | more
In such cases, it's only possible to exit 'more' by pressing 'q';
CTRL+C does not work.
Changes:
- Refactor more_poll() code:
- Introduce an enum to access pfd[] items instead of using magical constants.
- Implement a while() loop to handle EAGAIN or POLLHUP.
- Ignore stdin after POLLHUP (indicating that the pipe's peer closed).
- Ensure stderr is also checked.
- Use return codes akin to classic poll().
Note: I have doubts regarding the usability of stdin in more_poll(),
as the function is primarily used to wait for user input (via stderr)
and to monitor signals. Nevertheless, it is retained for potential use
in detecting when the pipe's peer (or the entire session) has been
terminated (see commit 68e14d3d5f4116ad3aca0e392d008645ea90cf70).