aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2024-10-08 17:01:46 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2024-10-08 17:01:46 +0000
commitc2d93a803acef634bd0eede6673aeea59e90c277 (patch)
tree1be11a024bf44d99cf3e7e6668d2296ddb0aff5f
parent6f6166e49c78f6460732c02bbbba6fcc218221cf (diff)
env: Check the status of stdout.
MFC after: 3 days Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D47009
-rw-r--r--usr.bin/env/env.c2
-rw-r--r--usr.bin/env/tests/env_test.sh17
2 files changed, 19 insertions, 0 deletions
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);
}
diff --git a/usr.bin/env/tests/env_test.sh b/usr.bin/env/tests/env_test.sh
index d49765a04f9a..2dc8f1a4c911 100644
--- a/usr.bin/env/tests/env_test.sh
+++ b/usr.bin/env/tests/env_test.sh
@@ -130,6 +130,22 @@ chdir_body()
env -C "${subdir}" pwd
}
+atf_test_case stdout
+stdout_head()
+{
+ atf_set descr "Failure to write to stdout"
+}
+stdout_body()
+{
+ (
+ trap "" PIPE
+ env 2>stderr
+ echo $? >result
+ ) | true
+ atf_check -o inline:"1\n" cat result
+ atf_check -o match:"stdout" cat stderr
+}
+
atf_init_test_cases()
{
atf_add_test_case basic
@@ -140,4 +156,5 @@ atf_init_test_cases()
atf_add_test_case altpath
atf_add_test_case equal
atf_add_test_case chdir
+ atf_add_test_case stdout
}