On Tue, Apr 15, 2025 at 8:32 PM Jim Meyering <j...@meyering.net> wrote: > On Tue, Apr 15, 2025 at 7:26 PM Grisha Levit <grishale...@gmail.com> wrote: > > On Tue, Apr 15, 2025 at 9:54 PM Jim Meyering <j...@meyering.net> wrote: > > > Whoa. Thanks. It looks like this is a >19-year-old bug in stream-close.c > > > Here's a tentative fix -- the ChangeLog entry still lacks details of > > > when it was introduced: > > > > - if (! fclose_fail) > > + if (!fclose_fail && !prev_fail) > > errno = 0; > > > > I wonder if this was intentional? Since close_stdout seems to be mostly used > > as an atexit function, errno may well have been set for some unrelated > > reason by the time this runs -- but errno will be relevant to this stream > > if fclose has just failed. > > I retract that patch. It was obviously wrong: it would render the > errno=0 statement unreachable.
We're going to have to revise that code. The difference I see is that before rawhide, that fclose would fail. It's perfectly fine for fclose to succeed in this case, as now happens on rawhide (because with 4k BUFSIZ, the fclose wrote nothing -- the preceding 4096-byte write is what failed). Here's a better patch: (technically, we could factor it somewhat, but readability would suffer disproportionately)
close-stream2.diff
Description: Binary data