Subject: Re: bug#77800: grep-3.12: write-error-msg test failure on fedora rawhide (f43)

From: Jim Meyering <[email-masked]>
Date: Thu, 17 Apr 2025 23:58:40 -0700

On Thu, Apr 17, 2025 at 11:15 PM Grisha Levit <[email-masked]> wrote:
>
> On Fri, Apr 18, 2025 at 1:51 AM Jim Meyering <[email-masked]> wrote:
> >
> > Surprised to find that coreutils-9.5 (fedora 41 stock) works fine:
> >
> >   $ { /bin/printf %4095s; /bin/printf %4096s; } > /dev/full
> >   /bin/printf: write error: No space left on device
> >   /bin/printf: write error: No space left on device
>
> Though OTOH (not sure why):
>
>     $ { /bin/printf %4096s; /bin/printf %4097s; } > /dev/full
>     /bin/printf: write error: No space left on device
>     /bin/printf: write error
>
> ----
>
> But I'm concerned that with this change because programs where:
>
>     1. errno is set by a failed (unchecked) write
>     2. errno is then set by some unrelated function
>     3. close_stdout() is arranged to run atexit
>     4. when close_stream() calls fclose() it does not fail
>
> will now erroneously report the error from the unrelated function
> when running close_stdout.
>
> Previously:
>
>     $ stdbuf -oL realpath -e . xxx >/dev/full
>     realpath: xxx: No such file or directory
>     realpath: write error
>
> After the patch:
>
>     $ stdbuf -oL src/realpath -e . xxx >/dev/full
>     realpath: xxx: No such file or directory
>     realpath: write error: No such file or directory

I think I've finally paged back in all of that from 20 years ago.
And I agree: there is no need for my most recent proposed change.
When fclose succeeds, yet there was a "prev_failure" but no fclose
failure, we cannot guarantee errno is relevant, so clearing it **is**
appropriate.
Now, as for what changed in F42 to make us go from printing the ENOSPC
expansion to not printing it, so far I haven't reproduced the failure.
Just built there and this works just as it does on F41:

$ src/grep --help > /dev/full

                                      :
src/grep: write error: No space left on device