On Tue, 15 Jul 2025, 03:46 Robert Elz, <k...@munnari.oz.au> wrote: > | > 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 I'd be reporting that as a kernel bug.
But linux seems to be filled with crap like that. > Leaving side race conditions on any multiprocessing system, this is an issue applicable to any generated content. For stat to give an accurate answer, a snapshot of the content would have to be generated, counted, and discarded, all of which would make the stat syscall much slower, even when the client program is going to ignore the file size. Arguably these files that read out kernel state are more like a pipes or sockets than plain files, but many utilities check and refuse to open anything except plain files, which would make /proc and /sys much less convenient to use. I guess fstat could give an accurate answer without incurring adding additional cost. All that said, I don't see why this needs to be treated as an error condition. When I learned UNIX programming a long time ago, the rule for syscalls was: don't ask a question to decide whether to try something, just try it and see. There are always exceptions where you need to co-ordinate transactions, but checking the file size and then failing when the file size changes, is exactly the kind of issue that rule was designed to avoid. -Martin >