Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 09 Oct 2024 21:29:23 +0200
From:      Steffen Nurpmeso <steffen@sdaoden.eu>
To:        Kyle Evans <kevans@FreeBSD.org>
Cc:        Konstantin Belousov <kostikbel@gmail.com>, src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org, Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@freebsd.org>
Subject:   Re: git: c2d93a803ace - main - env: Check the status of stdout.
Message-ID:  <20241009192923.hYP_AEIt@steffen%sdaoden.eu>
In-Reply-To: <91c60145-9f13-48a6-b7cd-4a1a9703e67c@FreeBSD.org>
References:  <202410081702.498H2KIP072012@gitrepo.freebsd.org> <ZwVuwK9Lry_6JDay@kib.kiev.ua> <86iku2v3o2.fsf@ltc.des.dev> <ZwZ0erARk2ZKAeBv@kib.kiev.ua> <91c60145-9f13-48a6-b7cd-4a1a9703e67c@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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=C3=B8rgrav wrot=
e:
 |>> Konstantin Belousov <kostikbel@gmail.com> writes:
 |>>> Dag-Erling Sm=C3=B8rgrav <des@FreeBSD.org> writes:
 |>>>> +        if (fflush(stdout) !=3D 0)
 |>>>> +                err(1, "stdout");
 |>>> Why is this check needed?
 |>>
 |>> POSIX requires it.
 |> Could you please point me to the requirement?
 |>=20
 |
 |Seconding the assertion that it's somewhere in there, but it's also just=
=20
 |a reasonable thing to do.  The implicit flush at exit of streams in libc=
=20
 |has to ignore errors because it lacks the necessary context to be able=20
 |to surface anything, so applications must do it on an individual basis=20
 |to appropriately surface, e.g., output truncation issues that are=20
 |otherwise hidden (and maybe not obvious) from the caller.
 |
 |The impression I had from talking to folks about this in the past is=20
 |that it's practically expected that applications will flush-and-error at=
=20
 |the end rather than check individual writes so that they can surface=20
 |logic/execution errors at a higher priority than stdout errors, but=20
 |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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20241009192923.hYP_AEIt>