On 11/20/25 11:49 AM, Martin Wilck wrote:
Date: Thu 20 Nov 2025 04:49:01 PM UTC By: Martin Wilck <mwilck>
Linux uevent files contain lines in "VAR=value" style. It's a common idiom under Linux to source uevent files with the shell and print the value of some variable, like this: # cat /sys/class/block/sda/uevent MAJOR=8 MINOR=0 DEVNAME=sda DEVTYPE=disk DISKSEQ=1 # (. /sys/class/block/sda/uevent; echo "$DEVNAME") sda The expected output is "sda". This was the case with bash 5.2 and earlier versions, and is also the case with other shells. But with bash 5.3, an error is reported and the result is an empty string: # (. /sys/class/block/sda/uevent; echo "$DEVNAME") bash: /sys/class/block/sda/uevent: Success
Bash-5.3 checks whether or not the size of a regular file as reported by stat(2) matches the number of bytes read. It uses the size to allocate a buffer, so it can read the file in one chunk. That code went in in early 2023 as the result of a discussion about parser errors and EOF, and whether the shell should exit as a result. This uevent issue originally came up in July, in https://lists.gnu.org/archive/html/bug-bash/2025-07/msg00031.html I've appended the patch that resulted from the discussion.
The problem is co-caused by the fact that the Linux kernel reports a size of 4k for every regular file: # stat -c %s /sys/class/block/sda/uevent 4096
Yes, this defeats the bash check. I tend to agree with kre that this is
a Linux kernel bug, but here we are.
*** ../bash-5.3-patched/builtins/evalfile.c Fri Sep 6 15:42:40 2024
--- builtins/evalfile.c Fri Sep 12 11:38:57 2025
***************
*** 161,166 ****
--- 161,168 ----
if (nr >= 0)
string[nr] = '\0';
+ #if 0
if (nr != file_size)
nr = -1; /* XXX - didn't get the whole file */
+ #endif
}
else
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
