Date: Fri, 16 May 2025 14:56:38 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: fbaba7aa4322 - main - man: Exit cleanly on SIGPIPE. Message-ID: <202505161456.54GEucs8015082@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=fbaba7aa432257a9b787edc6bfdbfbde94f2e0d5 commit fbaba7aa432257a9b787edc6bfdbfbde94f2e0d5 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-16 14:56:25 +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. PR: 223516, 279542 Fixes: 14a5c1068d37, a85d870007e7 MFC after: 1 week Reviewed by: ziaee, kevans Differential Revision: https://reviews.freebsd.org/D50302 --- 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 68a4b3a40588..ec20fc813bf4 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 @@ -1061,6 +1064,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} }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505161456.54GEucs8015082>