Karel Zak [Mon, 17 Apr 2023 09:25:09 +0000 (11:25 +0200)]
Merge branch 'fadvise/fixes' of https://github.com/t-8ch/util-linux
* 'fadvise/fixes' of https://github.com/t-8ch/util-linux:
fadvise: always exit with EXIT_FAILURE on error
fadvise: (man) document help and version arguments
fadvise: correctly report error from posix_fadvise
fadvise: implement --advice argument
Karel Zak [Mon, 17 Apr 2023 08:57:45 +0000 (10:57 +0200)]
Merge branch 'correct_blkid_xfs_output' of https://github.com/jlinton/util-linux
* 'correct_blkid_xfs_output' of https://github.com/jlinton/util-linux:
libblkid: Compute CRC with sb_crc zeroed
lib: Add crc32c function that can deal with holes
Jeremy Linton [Fri, 14 Apr 2023 21:25:28 +0000 (16:25 -0500)]
libblkid: Compute CRC with sb_crc zeroed
The Linux kernel computes the sb_crc by crcing the
superblock with the CRC field set to 0. The code is
trying to avoid doing this in three separate CRC calls
like the kernel performs by simply zeroing the field
and making a single call.
Except that the passed copy "ondisk" isn't the same
as the returned copy "csummed" so the zeroing goes into
the wrong buffer. Meaning that the CRC is computed
incorrectly. This results in blkid returning:
Which can result in lots of failures including boot
failures if XFS modules aren't placed into the initrd,
or scripts/etc cannot determine the fs UUID.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Jeremy Linton [Fri, 14 Apr 2023 23:07:29 +0000 (18:07 -0500)]
lib: Add crc32c function that can deal with holes
XFS, and possibly other filesystems expect that the CRC field
is excluded (or rather RAZ) during the CRC operation. Lets
create a generic helper that is similar to the CRC32 version
ul_crc32_exclude_offset() which computes the CRC while replacing
exclude_len bytes of exclude_off with zeros.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Karel Zak [Tue, 11 Apr 2023 10:04:30 +0000 (12:04 +0200)]
Merge branch 'hwclock/cleanup' of https://github.com/t-8ch/util-linux
* 'hwclock/cleanup' of https://github.com/t-8ch/util-linux:
hwclock: use linux/rtc.h
hwclock: drop ancient sparc special cases
hwclock: constify struct clock_opts
hwclock: (tests) add simple test to show rtc time
Karel Zak [Wed, 5 Apr 2023 19:44:55 +0000 (21:44 +0200)]
libmount: fix superblock rw/ro reconfiguration
The classic mount(2) defaults to 'rw', but the new API does not reset
superblock to 'rw' if the flag is not explicitly used for
FSCONFIG_CMD_RECONFIGURE.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2180593 Signed-off-by: Karel Zak <kzak@redhat.com>
For a long time, since commit 607ca46e97a1 ("UAPI: (Scripted) Disintegrate include/linux")
the kernel provided a dedicate uapi include for RTC definitions.
This makes the comment linux/mc146818rtc.h obsolete.
nsenter: use explicit argument to follow target PID/GID
Making the argument to -S and -G optional in #2092 broke the cli
compatability.
So replace it with an explicit "follow" argument that provides the new
functionality with a compatible interface.
Stephen Kitt [Sat, 25 Mar 2023 08:30:22 +0000 (09:30 +0100)]
mount: relatime allows equality
relatime also updates atime if the previous atime is equal to one or
both of the ctime and mtime; a non-strict interpretation of "earlier
than" allows this, but for clarity, this makes it explicit.
Pointed out by "epiii2" and "ctrl-alt-delor" in
https://unix.stackexchange.com/q/740862/86440.
Ronan Pigott [Thu, 23 Mar 2023 22:18:00 +0000 (15:18 -0700)]
hexdump-parse: handle truncated format pattern
If the fmt being parsed by block_size is exactly '%', *++fmt is the
terminator and strchr will return a valid pointer to the terminator of
spec rather than NULL, the while condition will pass and subsequent
strchr will read past the end of fmt until a spec character is found
again
ASAN aborts with the following error on the first buffer overread:
AddressSanitizer: heap-buffer-overflow on address 0x602000000212 at pc 0x55bf1c4b2d78 bp 0x7ffe33c8cff0 sp 0x7ffe33c8cfe0
READ of size 1 at 0x602000000212 thread T0
#0 0x55bf1c4b2d77 in block_size ../text-utils/hexdump-parse.c:207
#1 0x55bf1c4ad36f in main ../text-utils/hexdump.c:214
#2 0x7f15f063c78f (/usr/lib/libc.so.6+0x2378f)
#3 0x7f15f063c849 in __libc_start_main (/usr/lib/libc.so.6+0x23849)
#4 0x55bf1c4ac6c4 in _start (../build/hexdump+0x86c4)
Karel Zak [Thu, 23 Mar 2023 20:19:11 +0000 (21:19 +0100)]
Merge branch 'xry111/lscpu-loongarch' of https://github.com/xry111/util-linux
* 'xry111/lscpu-loongarch' of https://github.com/xry111/util-linux:
lscpu: Add loongarch testcase
lscpu: Add "ISA" field into lscpu_cputype and determine loongarch op-mode from its value
lscpu: Parse loongarch specific lines
Karel Zak [Thu, 23 Mar 2023 14:25:00 +0000 (15:25 +0100)]
libmount: fix MS_REMOUNT emulation by mount_setattr()
The classic mount(MS_REMOUNT) means that all unspecified MS_NOxxx
flags are remove (except MS_NOATIME). We need to follow this semantic
when emulate remount by mount_setattr(), because "mount -o remount /"
is the way how (for example) systemd resets root filesystem to default
(e.g. ro->rw, etc.)
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2180593 Signed-off-by: Karel Zak <kzak@redhat.com>
Xi Ruoyao [Wed, 22 Mar 2023 12:44:19 +0000 (20:44 +0800)]
lscpu: Parse loongarch specific lines
/proc/cpuinfo on loongarch uses UPPERCASE letters in some field names.
Add the patterns for them.
"Address Sizes", "CPU Family", "CPU Revision" (aka "Model"), and
"Model Name" are correctly outputed, but "CPU MHz" not (because we
don't have a CPUFreq driver yet).
наб [Wed, 15 Mar 2023 15:16:48 +0000 (16:16 +0100)]
wall: use fputs_careful()
LINE_MAX only applies to teletypes in canonical mode: when stdin is a
file, it could still very much tear; start off at 512 for the sprintf(),
then use getline() like in write.
The line wrapping has one suboptimal edge-case:
$ wall < all
Broadcast message from nabijaczleweli@tarta (pts/4) (Tue Mar 14 22:31:25
2023):
^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJ
KLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?\200\201\202\203\204\205\206
\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232
\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256
\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302
\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326
\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352
\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376
\377
but that's a pathological input, and the result is still infinitely
better than it was before, so fixing that is more trouble than it's
worth.
наб [Wed, 15 Mar 2023 15:16:43 +0000 (16:16 +0100)]
wall: convert homebrew buffering to open_memstream()
The struct buffer system duplicates a plethora of standard I/O
functions (including a fork of fputc_careful())
and adds a lot of complexity ‒ open_memstream() is standard,
and fits perfectly into this niche
наб [Wed, 15 Mar 2023 15:16:31 +0000 (16:16 +0100)]
write: correctly handle wide characters
Do this by replacing fputc_careful() (notice that the description said
it's locale-aware ‒ it very much is /not/), with a fputs_careful() which
does the same thing, but if it were to output a byte in the \123 format,
first it checks whether this byte starts a valid multibyte character.
If it does, and that character is printable, write it verbatim.
This means that
echo 'foo åäö ąęćźżń bar' | write nabijaczleweli pts/4
instead of
foo \303\245\303\244\303\266
\304\205\304\231\304\207\305\272\305\274\305\204 bar
yields
foo åäö ąęćźżń bar
or, more realistically, from a message I got earlier today,
Filip powiedzia\305\202 \305\274e zap\305\202aci jutro
becomes
Filip powiedział że zapłaci jutro
Invalid/non-printable sequences get processed as before.
Line reading in write must become getline() to avoid dealing with
partial characters: for example on input consisting solely of
ąęćźżń, where every {1} is an instance, the output would be
{42}ąęć\305\272żń{84}ąęćź\305\274ń{84}ąęćźż\305\204{39}
with just fixed-512 fgets()
наб [Thu, 16 Mar 2023 16:08:59 +0000 (17:08 +0100)]
lsfd: error if extraneous argument given
The manual and help string both spec lsfd [options];
actually stick to that instead of ignoring subsequent arguments.
This is particularly a weird thing to allow given that lsof path
is legal and does something (either same as
lsfd -Q "MAJ:MIN == \"$(stat -c %Hd:%Ld path)\"" if it's a mountpoint or
lsfd -Q "NAME ~= '$path'" (sans the regex and escaping) otherwise).