Re: sourc. can't handle /sys/block/*/uevent on Linux
From:
Chet Ramey
Subject:
Re: sourc. can't handle /sys/block/*/uevent on Linux
Date:
Mon, 14 Jul 2025 10:52:50 -0400
User-agent:
Mozilla Thunderbird
On 7/12/25 12:52 PM, Emanuele Torre wrote:
User zen_desu mentioned this bug report on the #bash IRC channel of
libera.chat today: https://github.com/desultory/ugrd/pull/328
Basically, in bash 5.3, if you try to source a /sys/block/*/uevent file;
example:
$ cat /sys/block/sda/uevent
MAJOR=8
MINOR=0
DEVNAME=sda
DEVTYPE=disk
DISKSEQ=1
source or . will fail printing the error message"bash: ${file}: Success"
Hmmmm. Let's see here.
One of the assumptions bash makes is that when the kernel tells it the size
of a regular file using stat(2), it's telling the truth, and that reading
fewer bytes than that when asking for the entire file indicates some kind
of problem.
This happens because /sys/block/*/uevent show up as regular files, and
reports a file size of 4096 in stat:
Which isn't the true file size.
..and there is a new check in evalfile_internal() that treats like an
error to not get filesize bytes after one read from a regular file
(given a large enough buffer)
Yes. It seems like that assumption isn't valid on Linux.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/