git: 84b971c9186a - releng/14.3 - man: Exit cleanly on SIGPIPE.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 21 May 2025 17:37:25 UTC
The branch releng/14.3 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=84b971c9186ad241151a84bbbfb9218adc54df6c
commit 84b971c9186ad241151a84bbbfb9218adc54df6c
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-05-16 14:56:13 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-05-21 17:36:41 +0000
man: Exit cleanly on SIGPIPE.
The first attempt at addressing this simply suppressed SIGPIPE, which
resulted in mandoc printing out error messages instead. This was then
reverted, but the pipefail was (correctly) left in, so man still
returned a nonzero exit code if you quit a page before the end.
Approved by: re (cperciva)
PR: 223516, 279542
Fixes: 14a5c1068d37, a85d870007e7
MFC after: 1 week
Reviewed by: ziaee, kevans
Differential Revision: https://reviews.freebsd.org/D50302
(cherry picked from commit fbaba7aa432257a9b787edc6bfdbfbde94f2e0d5)
(cherry picked from commit 2f99190a9234b119bcec1e4645e87d4e6016e5a5)
---
usr.bin/man/man.sh | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh
index 341a57c6d7dc..b1cfc6c41752 100755
--- a/usr.bin/man/man.sh
+++ b/usr.bin/man/man.sh
@@ -33,7 +33,10 @@
# it is better to terminate it.
ulimit -t 20
-# do not ignore the exit status of roff tools
+# Do not ignore the exit codes of roff tools, as they may indicate a
+# problem with the page being rendered. Note that this also causes a
+# nonzero exit when the user quits reading before reaching the end, so
+# we need to look out for and deal with that specific case.
set -o pipefail
# Usage: add_to_manpath path
@@ -1055,6 +1058,16 @@ do_man() {
man_find_and_display "$page"
done
+ # The user will very commonly quit reading the page before
+ # reaching the bottom. Depending on the length of the page
+ # and the pager's buffer size, this may result in a SIGPIPE.
+ # This is normal, so convert that exit code to zero.
+ if [ ${ret:-0} -gt 128 ]; then
+ if [ "$(kill -l "${ret}")" = "PIPE" ]; then
+ ret=0
+ fi
+ fi
+
exit ${ret:-0}
}