From nobody Wed Oct  9 19:29:23 2024
X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XP3cC0JwQz5YwMP;
	Wed, 09 Oct 2024 19:58:51 +0000 (UTC)
	(envelope-from steffen@sdaoden.eu)
Received: from sdaoden.eu (sdaoden.eu [217.144.132.164])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(Client did not present a certificate)
	by mx1.freebsd.org (Postfix) with ESMTPS id 4XP3cB4qsxz4Sy4;
	Wed,  9 Oct 2024 19:58:50 +0000 (UTC)
	(envelope-from steffen@sdaoden.eu)
Authentication-Results: mx1.freebsd.org;
	none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sdaoden.eu;
 s=citron; t=1728503921; x=1729170587; h=date:author:from:to:cc:subject:
  message-id:in-reply-to:references:mail-followup-to:openpgp:blahblahblah:
  mime-version:content-type:content-transfer-encoding:author:from:subject:
  date:to:cc:resent-author:resent-date:resent-from:resent-sender:resent-to:
  resent-cc:resent-reply-to:resent-message-id:in-reply-to:references:
  mime-version:content-type:content-transfer-encoding:content-disposition:
  content-id:content-description:message-id:mail-followup-to:openpgp:
  blahblahblah; bh=7tWWpKKkeRydccHjBhxMKNGzA3meQ3M4davhQlW2GLQ=;
 b=Q+sqhYUEU+Su50y6VNtxbdPwxYHm2KwIZkiVnF/2QA+hr6FXk5vJEWLWkyidyivk6hGbcilH
  C9lHwzxGds6gNE0+ADfZhJ7/JksvMPcBMZ+tjhJARiPx82+tWT5dUoGvabJdKwztf4coB1AloP
  +FlNee5E4lro2rQUy1wOswRW0xGsfZySNNkupzHiBe/jp/6jeOD0HBnRp7uPSXRwnLSThEa2Sy
  BW+on2ZSXBOSHcaFPUY/kONJ/TnX5M3OhKrjj83MAnSy0Gd986ID9THOJN5n/dWh0rEFkQUanm
  lKRTXVZLV85tFSAgauiEVAyJk4/y9+HQKBU1mLEbW+wJCMqw==
DKIM-Signature: v=1; a=adaed25519-sha256; c=relaxed/relaxed; d=sdaoden.eu;
 s=orange; t=1728503921; x=1729170587; h=date:author:from:to:cc:subject:
  message-id:in-reply-to:references:mail-followup-to:openpgp:blahblahblah:
  mime-version:content-type:content-transfer-encoding:author:from:subject:
  date:to:cc:resent-author:resent-date:resent-from:resent-sender:resent-to:
  resent-cc:resent-reply-to:resent-message-id:in-reply-to:references:
  mime-version:content-type:content-transfer-encoding:content-disposition:
  content-id:content-description:message-id:mail-followup-to:openpgp:
  blahblahblah; bh=7tWWpKKkeRydccHjBhxMKNGzA3meQ3M4davhQlW2GLQ=;
 b=hKahXJQcU3yhekazOFphSbXiQosjHcbxraLXEYcOi/rkdZdz+wvtiAV7mM24/+NfyDdEdn8B
  TvpPjrRRJ2nIAQ==
Date: Wed, 09 Oct 2024 21:29:23 +0200
Author: Steffen Nurpmeso <steffen@sdaoden.eu>
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>
Mail-Followup-To: Kyle Evans <kevans@FreeBSD.org>,
 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>
User-Agent: s-nail v14.9.25-608-ge479530e8d
OpenPGP: id=EE19E1C1F2F7054F8D3954D8308964B51883A0DD;
 url=https://ftp.sdaoden.eu/steffen.asc; preference=signencrypt
BlahBlahBlah: Any stupid boy can crush a beetle. But all the professors in
 the world can make no bugs.
List-Id: Commit messages for all branches of the src repository <dev-commits-src-all.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all
List-Help: <mailto:dev-commits-src-all+help@freebsd.org>
List-Post: <mailto:dev-commits-src-all@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-all+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-all+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-all@freebsd.org
Sender: owner-dev-commits-src-all@FreeBSD.org
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-Rspamd-Pre-Result: action=no action;
	module=replies;
	Message is reply to one we originated
X-Spamd-Result: default: False [-4.00 / 15.00];
	REPLY(-4.00)[];
	ASN(0.00)[asn:15987, ipnet:217.144.128.0/20, country:DE]
X-Rspamd-Queue-Id: 4XP3cB4qsxz4Sy4
X-Spamd-Bar: ----

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)