Karel Zak [Tue, 29 Apr 2025 10:29:32 +0000 (12:29 +0200)]
hardlink: fix performance regression (inefficient signal evaluation)
During work on better verbose output, I found a regression between
v2.40 and v2.41 (and v2.42). In the new version, hardlink is 3-4 times
slower.
The problem is in the function where we verify signals. It calls the
function signal() even though no signal is delivered. It's called in
code loops where hardlink scans files, making it a performance-sensitive
area.
Another significant performance improvement is using an inline function
for handle_interrupt().
This simple patch improves hardlink performance by 10 times.
Fixes: http://github.com/util-linux/util-linux/commit/1453200e22dd4ec858be027653c167225f2fb358 Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 87831fa19e241803f93556cbeaad153e6ba89b6c)
Karel Zak [Tue, 29 Apr 2025 09:49:23 +0000 (11:49 +0200)]
hardlink: Use macro for verbose output
Now that jlog() is a function, all gettext() arguments are evaluated
in all cases, including when output is unnecessary due to --quiet or
low verbose mode.
Fixes: https://github.com/util-linux/util-linux/issues/3548 Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 5a2600c55f278c1252708cb3bdede92e27ccd04e)
Stanislav Brabec [Fri, 16 May 2025 01:10:14 +0000 (03:10 +0200)]
libblkid: Fix crash while parsing config with libeconf
As the whole econf_file structure is freed by econf_free(file) at the end
of blkid_read_config(), econf_file structure cannot be defined as static
and initialized only once. The econf_free() is not robust enough and keeps
a pointer to the garbage after the first call of blkid_read_config(). And
if /etc/blkid.conf does not exist, it is called second time.
Karel Zak [Thu, 22 May 2025 08:01:03 +0000 (10:01 +0200)]
lsblk: use ID_PART_ENTRY_SCHEME as fallback for PTTYPE
The udev database typically inherits the ID_PART_TABLE_TYPE property
from the entire disk device to its partitions. However, in some cases,
this property may be missing. Fortunately, blkid/udev also provides
ID_PART_ENTRY_SCHEME for all partitions.
Fixes: https://github.com/util-linux/util-linux/issues/3570 Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 23a7e0865ad56c46a69084974182b9979592b867)
remove two leftover license lines from colors.{c,h}
Last March, commit 549a517857 replaced the SPDX line in three files
with a "No copyright is claimed" phrase, but forgot to remove from
two of those files the text lines that correspond to the SPDX.
The documentation comment for scols_column_set_data_func was missing the
second asterisk in its opening marker, causing the contents to be
omitted from the rendered documentation.
Using strerror is not safe in shared libraries as it is unknown
what the calling apps may do with the storage behind the scenes.
Using %m is ok, except in contexts that need to be as-safe.
Thomas Weißschuh [Sat, 19 Apr 2025 20:02:11 +0000 (22:02 +0200)]
include/mount-api-utils: include linux/unistd.h
If SYS_statmount/SYS_listmount is not provided by the libc,
util-linux will fall back to __NR_statmount/__NR_listmount from the
kernel UAPI headers.
However it is not guaranteed that these symbols are actually visible in
mount-api-utils.
Include linux/unistd.h which provides syscall numbers.
While this header is specific to Linux, the code is already using
linux/mount.h.
Eugene Gershnik [Mon, 6 May 2024 16:29:39 +0000 (09:29 -0700)]
libuuid: fix uuid_time on macOS without attribute((alias))
Weak aliases are not supported by clang on Darwin.
Instead this fix uses inline asm to make `_uuid_time` an alias to
`___uuid_time`
It appears that on macOS the time API is purely 32 or 64 bit depending
on the build type. There is no ABI issue on that platform and `uuid_time`
can be unconditionally aliased to `_uuid_time`. This is all conjectural,
however, since I have no ability to make 32-bit builds for macOS - the
Apple toolchain doesn't support this since 2019.
Karel Zak [Mon, 7 Apr 2025 11:49:43 +0000 (13:49 +0200)]
treewide: fix optional arguments usage
In some parts of the code, the optional argument handling is missing
for cases where the argument starts with '='. This is particularly
important for short options with optional arguments, as suggested by
our man pages. The libc getopt_long() handles this for long options,
but for short options, it's our responsibility.
Note that some argument parsing functions (mostly colormode_or_err())
already implement this, as they are usually used with optional
arguments.
Thomas Devoogdt [Mon, 7 Apr 2025 12:20:12 +0000 (14:20 +0200)]
namespace.h: fix compilation on Linux < 4.10
sys-utils/lsns.c: In function ‘add_namespace_from_sock’:
sys-utils/lsns.c:580:19: error: ‘SIOCGSKNS’ undeclared (first use in this function)
nsfd = ioctl(sk, SIOCGSKNS);
^~~~~~~~~
run_shell() will implicitly execute the previous ctl->shell_line
not only if the function was indirectly invoked by the '.' command
but also by a subsequent '!' command.
Karel Zak [Wed, 2 Apr 2025 09:00:47 +0000 (11:00 +0200)]
include/cctype: fix string comparison
Reimplement c_strcasecmp() and c_strncasecmp() to be libc compatible
and fix c_strncasecmp() to avoid \0 misinterpretation. The original
implementation was pretty stupid (sorry).
Thomas Devoogdt [Tue, 25 Mar 2025 10:58:18 +0000 (11:58 +0100)]
lsns: fix undefined reference to add_namespace_for_nsfd #3483
Fixes:
sys-utils/lsns-lsns.o: In function `read_process':
lsns.c:(.text+0x9e8): undefined reference to `add_namespace_for_nsfd'
collect2: error: ld returned 1 exit status
Karel Zak [Thu, 20 Mar 2025 10:53:59 +0000 (11:53 +0100)]
column: fix compiler warning for non-widechar compilation
text-utils/column.c: In function ‘ansi_esc_width’:
text-utils/column.c:212:17: warning: case label value exceeds maximum value for type [-Wswitch-outside-range]
Karel Zak [Mon, 17 Mar 2025 12:38:20 +0000 (13:38 +0100)]
terminal-colors.d: support NO_COLOR
We already provide the ability to easily disable output colorization,
but there is also the https://no-color.org initiative based on the
NO_COLOR environment variable. Let's support this method to disable
colors. Let's be friendly :-)
Addresses: https://github.com/util-linux/util-linux/issues/3463 Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 61bd162fa1246a1d296cf943d12f7c01c8053b10)
Karel Zak [Mon, 17 Mar 2025 13:35:10 +0000 (14:35 +0100)]
include: use public domain for colors.{c,h} and xalloc.h
The LGPL makes it difficult to use the code in the old BSD tools we
have in util-linux. After obtaining agreement from the major
contributors to the files, we are changing it to "Public Domain".
Karel Zak [Mon, 17 Mar 2025 10:49:57 +0000 (11:49 +0100)]
more: fix repeat command
The function more_key_command() may modify the current command setting.
We need to remember the original unmodified version, as specified by
the user, as the previous command; otherwise, the output will be affected
by unexpected cmd.number settings.
Simple reproducer:
$ more -c /etc/passwd
- Press <enter> to jump to the next line.
- Press '.' to repeat the last command.
Old version:
- It clears the screen and prints only one line (like the "1 <enter>" command).
Fixed version:
- It jumps to the next line (like the "<enter>" command).
Reported-by: Benno Schulenberg <bensberg@telfort.nl> Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 5be4bdf81a8e89b98b12db275deb6154f87feb4b)
swapon: make options --help and --version override --summary
When -h or --help is among the given options, most utilities
print a help text, ignoring all other options and arguments.
Make `swapon --summary --help` conform to this general pattern.