git: 84090186db73 - stable/14 - pwd: Error out if writing to stdout failed
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 15 Feb 2026 08:58:46 UTC
The branch stable/14 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=84090186db732c299fd58f45d1396df1ff866920
commit 84090186db732c299fd58f45d1396df1ff866920
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-11 02:06:41 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-15 08:58:34 +0000
pwd: Error out if writing to stdout failed
POSIX requires us to print a diagnostic and return a non-zero exit
code if writing to stdout failed.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D55227
(cherry picked from commit 5b398611607b0dab2f2550ef73f62d41dab6fac5)
---
bin/pwd/pwd.c | 2 ++
bin/pwd/tests/pwd_test.sh | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c
index e8ce4cabc01a..d2d8fac4e4b2 100644
--- a/bin/pwd/pwd.c
+++ b/bin/pwd/pwd.c
@@ -124,5 +124,7 @@ main(int argc, char *argv[])
printf("%s\n", pwd);
else
err(1, ".");
+ if (fflush(stdout) != 0)
+ err(1, "stdout");
exit(0);
}
diff --git a/bin/pwd/tests/pwd_test.sh b/bin/pwd/tests/pwd_test.sh
index e418e56a89fa..a8805582cc4d 100644
--- a/bin/pwd/tests/pwd_test.sh
+++ b/bin/pwd/tests/pwd_test.sh
@@ -66,8 +66,29 @@ physical_body()
atf_check -o inline:"$root/phy/baz\n" pwd -L
}
+atf_test_case stdout
+stdout_head()
+{
+ atf_set descr "error writing to stdout"
+}
+stdout_body()
+{
+ pwd=$(which pwd)
+ [ -f "$pwd" ] || atf_skip "unable to distinguish binary from builtin"
+ (
+ trap "" PIPE
+ # Give true(1) some time to exit.
+ sleep 1
+ $pwd 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 logical
atf_add_test_case physical
+ atf_add_test_case stdout
}