diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh --- 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 @@ 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} }