Re: git: c2d93a803ace - main - env: Check the status of stdout.
- In reply to: Kyle Evans : "Re: git: c2d93a803ace - main - env: Check the status of stdout."
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 09 Oct 2024 19:29:23 UTC
Kyle Evans wrote in <91c60145-9f13-48a6-b7cd-4a1a9703e67c@FreeBSD.org>: |On 10/9/24 07:18, Konstantin Belousov wrote: |> On Tue, Oct 08, 2024 at 08:40:45PM +0200, Dag-Erling Smørgrav wrote: |>> Konstantin Belousov <kostikbel@gmail.com> writes: |>>> Dag-Erling Smørgrav <des@FreeBSD.org> writes: |>>>> + if (fflush(stdout) != 0) |>>>> + err(1, "stdout"); |>>> Why is this check needed? |>> |>> POSIX requires it. |> Could you please point me to the requirement? |> | |Seconding the assertion that it's somewhere in there, but it's also just |a reasonable thing to do. The implicit flush at exit of streams in libc |has to ignore errors because it lacks the necessary context to be able |to surface anything, so applications must do it on an individual basis |to appropriately surface, e.g., output truncation issues that are |otherwise hidden (and maybe not obvious) from the caller. | |The impression I had from talking to folks about this in the past is |that it's practically expected that applications will flush-and-error at |the end rather than check individual writes so that they can surface |logic/execution errors at a higher priority than stdout errors, but |stdout errors should still prevent a clean exit. The POSIX core developer Geoff Clare said on 2021-07-01, message 20210701104540.GA4023@localhost: ... |The standard says nothing about internal buffering; it just requires |pwd to write the directory to file descriptor 1. It also states that |exit status 0 means "successful completion". Together, these |requirements mean that a conforming pwd must not exit with status 0 |if it did not write the directory to fd 1. | |If an implementor chooses to buffer the output, then it is their |responsibility to check that the buffer is successfully flushed to |fd 1 before exiting with status 0. ... |As above, this is all irrelevant to what the standard requires. | |As far as implementation detail goes, obviously if pwd uses stdio |buffering then in order to conform to the standard it must explicitly |fflush(stdout) and check there was no write error before exiting. |I see from later in the thread that mksh has now been patched to do |exactly that. (Thanks Thorsten.) --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)