Re: git: c2d93a803ace - main - env: Check the status of stdout.

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Wed, 09 Oct 2024 12:18:02 UTC
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?

> 
> > Or, put it differently, why is it needed for env(1) but not any other
> > program that writes to stdout?
> 
> You mean like these?
> 
> % git -P grep -l 'err\(1, "stdout"\)'
> bin/cat/cat.c
> bin/date/date.c
> sbin/md5/md5.c
> usr.bin/asa/asa.c
> usr.bin/comm/comm.c
> usr.bin/ctags/ctags.c
> usr.bin/du/du.c
> usr.bin/env/env.c
> usr.bin/head/head.c
> usr.bin/join/join.c
> usr.bin/lastcomm/lastcomm.c
> usr.bin/locate/code/locate.code.c
> usr.bin/ncal/ncal.c
> usr.bin/sed/main.c
> usr.bin/tail/misc.c
> usr.bin/tsort/tsort.c
> usr.bin/w/w.c
> usr.bin/yes/yes.c
This is a mixed bag.

Some programs do this 'err(1, "stdout")' call due
to libxo error, which is not exactly due to stdout error state.

Other do check individual fwrite/fputc operations.

> 
> or these?
> 
> https://reviews.freebsd.org/D41390
> https://reviews.freebsd.org/D41408
> https://reviews.freebsd.org/D41413
> https://reviews.freebsd.org/D41414
> https://reviews.freebsd.org/D41417
> https://reviews.freebsd.org/D41418
> https://reviews.freebsd.org/D41422
> https://reviews.freebsd.org/D41423
> https://reviews.freebsd.org/D41424
> https://reviews.freebsd.org/D41427
> https://reviews.freebsd.org/D41428
> https://reviews.freebsd.org/D41432

Again, it is mixed stuff, sometimes it is libxo etc.