The following should work whether MANSECT is set in a man.conf file, via an environment variable, or via the -S flag. It fails in all cases. To reproduce: MANSECT=1p man 1p grep or man -S 1p 1p grep Expected output: No manual entry for grep Actual output: No manual entry for 1p No manual entry for grep To reproduce: MANSECT=3 man 1 grep or man -S 3 1 grep Expected output: No manual entry for 1 No manual entry for grep Actual output: grep(1) man page is displayed
There are 2 possible issues here: 1. Running "man -S 1p 1 grep" displays the grep(1) man page -- explicitly specifying mansect overrides -S/MANSECT. 2. "No manual entry for 1p" -- 1p is missing from the default sections list, so it's treated as man page name and not section. What is the real use case here that is broken?
The reason for filing this issue is to allow using custom sections, such as man1p (used on Linux for POSIX man pages). As can be seen in the first instance, because man is ignoring MANSECT it thinks 1p is a page and not a section so this is impossible. The second variation I posted is just to illustrate the same bug in a different way. Fixing the first will likely fix this. It's more simple and straightforward if what is considered a section is what the user specifies, falling back to the default otherwise. This will lead to consistent behavior instead of special casing "default sections" (this is how it works on Linux as well). Also, FYI, setting MANSECT in a file doesn't work at all because it reads the config file after already deciding on the default list.
Created attachment 242606 [details] patch to fix the issue
Comment on attachment 242606 [details] patch to fix the issue --- man.sh.orig 2023-06-05 09:11:06.617877000 +0000 +++ man.sh 2023-06-05 09:43:16.432524000 +0000 @@ -562,7 +562,7 @@ P) MANPAGER=$OPTARG ;; S) MANSECT=$OPTARG ;; a) aflag=aflag ;; - d) debug=$(( $debug + 1 )) ;; + d) ;; # handled in man_setup f) fflag=fflag ;; h) man_usage 0 ;; k) kflag=kflag ;; @@ -603,7 +603,7 @@ fi IFS=: - for sect in $man_default_sections; do + for sect in $MANSECT; do if [ "$sect" = "$1" ]; then decho "Detected manual section as first arg: $1" MANSECT="$1" @@ -619,6 +619,15 @@ # Usage: man_setup # Setup various trivial but essential variables. man_setup() { + local cmd_arg + # Parse the debug flag prior to everything + OPTIND=1 + while getopts ':d' cmd_arg; do + case "${cmd_arg}" in + d) debug=$(( $debug + 1 )) ;; + esac + done + # Setup machine and architecture variables. if [ -n "$mflag" ]; then MACHINE_ARCH=${mflag%%:*} @@ -787,8 +796,8 @@ trim "${line#MANCONFIG}" config_local="$tstr" ;; - # Set variables in the form of FOO_BAR - *_*[\ \ ]*) var="${line%%[\ \ ]*}" + # Set other variables + *[\ \ ]*) var="${line%%[\ \ ]*}" trim "${line#$var}" eval "$var=\"$tstr\"" decho " Parsed $var" 3 @@ -1008,12 +1017,12 @@ } do_man() { + man_setup "$@" man_parse_args "$@" if [ -z "$pages" -a -z "${Kflag}" ]; then echo 'What manual page do you want?' >&2 exit 1 fi - man_setup if [ ! -z "${Kflag}" ]; then # Short circuit because -K flag does a sufficiently
Created attachment 242612 [details] improved patch
Created attachment 242613 [details] fix issues in last patch
Created attachment 242614 [details] fix whatis and apropos
Please ignore the patches, I've created a PR instead - https://github.com/freebsd/freebsd-src/pull/764.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8edb6fb572f29578877fdac3c30f718e589a0360 commit 8edb6fb572f29578877fdac3c30f718e589a0360 Author: Mohamed Akram <mohd.akram@outlook.com> AuthorDate: 2023-06-27 13:51:24 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2023-06-27 13:51:27 +0000 man(1): Support custom sections PR: 271830 Signed-off-by: Mohamed Akram <mohd.akram@outlook.com> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/764 usr.bin/man/man.sh | 70 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 25 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=b8f3f97c5ce240c156fab0205e0e3938196ed1e2 commit b8f3f97c5ce240c156fab0205e0e3938196ed1e2 Author: Wolfram Schneider <wosch@FreeBSD.org> AuthorDate: 2023-06-27 13:51:24 +0000 Commit: Wolfram Schneider <wosch@FreeBSD.org> CommitDate: 2024-02-12 15:41:01 +0000 man(1): Support custom sections PR: 271830 Signed-off-by: Mohamed Akram <mohd.akram@outlook.com> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/764 (cherry picked from commit 8edb6fb572f29578877fdac3c30f718e589a0360 - needed for further bugfixes) usr.bin/man/man.sh | 76 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 28 deletions(-)