Re: git: c2d93a803ace - main - env: Check the status of stdout.
Date: Tue, 08 Oct 2024 17:41:20 UTC
On Tue, Oct 08, 2024 at 05:02:20PM +0000, Dag-Erling Smørgrav wrote: > The branch main has been updated by des: > > URL: https://cgit.FreeBSD.org/src/commit/?id=c2d93a803acef634bd0eede6673aeea59e90c277 > > commit c2d93a803acef634bd0eede6673aeea59e90c277 > Author: Dag-Erling Smørgrav <des@FreeBSD.org> > AuthorDate: 2024-10-08 17:01:46 +0000 > Commit: Dag-Erling Smørgrav <des@FreeBSD.org> > CommitDate: 2024-10-08 17:01:46 +0000 > > env: Check the status of stdout. > > MFC after: 3 days > Sponsored by: Klara, Inc. > Reviewed by: markj > Differential Revision: https://reviews.freebsd.org/D47009 > --- > usr.bin/env/env.c | 2 ++ > usr.bin/env/tests/env_test.sh | 17 +++++++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c > index bb83baee114f..10e333602ee8 100644 > --- a/usr.bin/env/env.c > +++ b/usr.bin/env/env.c > @@ -214,6 +214,8 @@ main(int argc, char **argv) > } > for (ep = environ; *ep; ep++) > (void)printf("%s%c", *ep, term); > + if (fflush(stdout) != 0) > + err(1, "stdout"); > exit(0); Why is this check needed? Or, put it differently, why is it needed for env(1) but not any other program that writes to stdout?