Home | History | Annotate | Download | only in man
History log of /src/usr.bin/man/man.c
RevisionDateAuthorComments
 1.75  08-Sep-2025  jschauma Fix comment: '-f' and '-k' are in fact documented these days
 1.74  02-Sep-2025  christos PR/59625: Ingo Schwarze: Add a new -l flag that specifies to interpret
arguments as filenames, keeping the current behavior of interpreting
arguments as filenames if they begin with "/" "./" or "../" for compatibility.
In the future we can remove that.
 1.73  10-May-2022  gutteridge man.c: minor KNF
 1.72  08-Mar-2022  rillig man: remove unused global variable 'instype' (since yesterday)

No functional change.
 1.71  08-Mar-2022  rillig man: remove trailing whitespace

No binary change.
 1.70  08-Mar-2022  rillig man: fix type mismatch between enum and int (since yesterday)

No binary change.
 1.69  07-Mar-2022  gutteridge man.c: fix -m option so it works as documented

Refactoring work in man.c r. 1.40 from twelve years ago introduced a
regression where input from the -m option was appended rather than
prepended to the search paths. Problem reported by C. Chapman on
netbsd-users.
 1.68  06-Apr-2020  maya Exit successfully after printing the search path, stop further processing.

Continuing to process had the unintended effect that `man` failed to find
a matching manual page for {EMPTY LIST OF REQUESTED MANUAL PAGES}, and
exited with 1.

Prompted by a fish shell snippet that tried and failed to distinguish between
FreeBSD man (-p takes argument) and NetBSD man (-p no argument) by comparing
`man -p` exit code.

ok riastradh, logix (which also pointed out the manual page SYNOPSIS is
saying man -p should be used this way).
 1.67  15-Jun-2018  mrg branches: 1.67.2; 1.67.4;
move 'utsname' to the main() function scope, so that the reference to
it outside the block remains valid.

should fix an asan reported issue.
 1.66  02-May-2017  abhinav branches: 1.66.2; 1.66.8;
Teach man -p to respect the MANPATH environment variable and the -M option.

Currently, `man -p` generates its output based on the value of the _default tag
in man.conf. However, man(1) modifies its search path based on the value of the
MANPATH variable and the list of directories specified via the -M option. In such
a case, `man -p` does not represent the correct search path. This commit intends
to fix this.

This change has the side effect that now the output of `man -p` will also include
the machine class specific subdirectories (such as man8/x86), while previously it
did not. The output would include subdirectories only for those machine classes
which are specified in the man.conf file.

Also, with this change, it is possible to run makemandb(8), by setting MANPATH
environment variable (e.g. env MANPATH=/usr/share/man makemandb).

Patch reviewed by wiz@
 1.65  27-Apr-2017  abhinav Fix comment indentation at couple of places: Use \t instead of space
 1.64  16-Jun-2016  abhinav branches: 1.64.6;
Document -f option for man(1).
Also remove unsupported options for `man -k` from the synopsis and usage.
 1.63  21-May-2016  abhinav Remove unused include and unused constant. Ok from christos@.
 1.62  14-Aug-2014  apb For an argument to be interpreted as a local file name, bypassing the
search rules in man.conf or MANPATH, it must begin with "/", "./", or
"../". Simply testing whether it contains "/" is wrong, because it
breaks usage like "man 8 vax/boot".

This reverts revision 1.57 dated 2013-10-06,
"Be more permissive in interpreting man pages as filenames".
 1.61  17-Feb-2014  uwe branches: 1.61.4;
config() in manconf.c now verifies _build (and _crunch) command
templates with fmtcheck(3) so annotate the printf that uses these
commands as safe with a __format_arg wrapper and drop
-Wno-format-nonliteral.

XXX: Using local wrapper for now, solving this in general would be
nice, but it raises namespace pollution issues.

XXX^2: catman(8) also uses manconf.c and uses _build and _crunch so it
can also benefit from this (but see above).
 1.60  28-Oct-2013  christos Instead of guessing the suffix in the code, use the suffix list previously
loaded via man.conf(5). While there, zap unused iteration code.
(Franco Fichtner)
 1.59  06-Oct-2013  christos add more compression suffixes and local suffixes.
 1.58  06-Oct-2013  christos Recognize .gz and .bz2 suffixes so $ man ./man.1.gz works. From Franco Fichter
via dfly.
 1.57  06-Oct-2013  christos Be more permissive in interpreting man pages as filenames, from Franco
Fichter via dfly. fixes:
$ man usr.bin/man/man.1
 1.56  30-Jul-2013  joerg Mark the dead.
 1.55  19-Jul-2013  uwe Constify some more.
 1.54  19-Jul-2013  uwe Spell "keywords" without space. Fix couple of typos.
 1.53  19-Jul-2013  uwe manual_find_buildkeyword() - now that we control the format string, we
may use asterisk precision specification instead of temporary
modifying the _build string itself.
 1.52  19-Jul-2013  uwe Fix manual_find_buildkeyword() to not use non-literal printf format.
 1.51  18-Jul-2013  uwe Don't access memory outside the array if tmpdirlen == 0.
 1.50  18-Jul-2013  christos use -Wno-format and revert "fixstring"
 1.49  18-Jul-2013  christos Set the string to NUL instread of providing an new empty string (from uwe)
 1.48  18-Jul-2013  christos WARNS=6
- fix cast qual issues
- don't use snprintf on a user-provided buffer
 1.47  18-Jul-2013  uwe Revert previous; other errors from WARNS=3 obscured the error in jump().
 1.46  18-Jul-2013  uwe Constify jump() arguments appropriately.
 1.45  18-Jul-2013  uwe Move manstate::pagerlen so that its "length of the above" comment makes sense.
 1.44  03-Jan-2012  joerg branches: 1.44.6; 1.44.10;
If the default path doesn't result in a match, bail out early instead of
running into a segmentation fault. Based on patch by Abhinav Upadhyay.
 1.43  14-Jun-2011  wiz branches: 1.43.2;
Fix usage in man page and sync usage in executable with it.
 1.42  14-Jun-2011  joerg Add support for man -p to print the search path for manual pages (not
including cat page directories).

From Abhinav Upadhyay as part of Google's Summer of Code 2011
 1.41  07-Jul-2010  christos branches: 1.41.4;
get the value of the entry for the class not the key.
 1.40  23-May-2010  christos - centralize the snprintf code.
- use err where appropriate.
- add machclass which should be x86 when i386 and amd64 and can be specified
in man.conf as:
_i386 x86
_amd64 x86
so that we can support merged pages. Nothing uses this yet.
 1.39  07-Oct-2009  cegger Mimic OSX behaviour:

On OS X it is possible to specify the manpage filename
with a full or relative path like this:

man ./foo.5

or

man /cd/foo/bar.1.gz

This is really helpful to view the manpage quickly while editing it.

patch presented on current-users@ and tech-userlevel@:
http://mail-index.netbsd.org/current-users/2009/10/06/msg010767.html
http://mail-index.netbsd.org/tech-userlevel/2009/10/06/msg002675.html

No objections
 1.38  06-Oct-2009  cegger - use EXIT_FAILURE/EXIT_SUCCESS
- whitespace nits
- ansify cleanup()/usage()
- remove pointless parenthesis on return
 1.37  21-Jul-2008  lukem branches: 1.37.4; 1.37.10;
Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.36  05-Oct-2007  lukem branches: 1.36.8;
Convert to using raise_default_signal(3).
 1.35  05-Feb-2007  jwise branches: 1.35.4;
Since MAN_DEBUG is constant, go from if (MAN_DEBUG) to #if MAN_DEBUG
 1.34  01-May-2006  christos Coverity CID 2996: Don't return without closing fp.
 1.33  10-Apr-2006  chuck modified man(1):
- avoid double slashes when displaying man pages (got tired
of '/usr/share/man//cat1/man.0').
- got rid of __P() while working on it.
- incorporate some of my old notes explaining how manpath works into the
comments of the code itself.
- renamed some of the vars so that the code is consistent throughout
(and hopefully clearer and easier to understand)
- fixed relative man paths for multiple man pages (man did a chdir()
on the first man page it had to format --- this broke any remaining
relative path man pages left to process). save old directory and
fchdir() back to it after formatting.
- improved doc on "man -h" which does more than just whatis(1) [e.g.
"man -h fopen" prints the required include files and the prototypes
rather than just the one-liner you get with whatis(1)]
- manconf.c now fills in the "len" length field in the TAG/ENTRY
structures (man now uses len).

revise man.conf file reading stuff to return error on failure in
addentry/gettag (fka getlist) rather than just err()ing out. this
allows man(1) to call cleanup and delete its tmp files rather than
just leave them floating. revise other apps using this code
(makewhatis, apropos, catman, whatis) to expect this. also remove
__P on updated files.
 1.32  08-Apr-2006  christos change an int to size_t
 1.31  05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.30  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.29  13-Sep-2002  thorpej Rename man/config.{c,h} to man/manconf.{c,h}, so we don't have to
worry about problems including "config.h" when building as a host
tool.
 1.28  11-Jun-2002  lukem - getlist(): add "int create" arg, which creates list if it's not present
(using guts of now defunct addlist())
- use TAILQ_*() macros appropriately when manipulating tailqs
 1.27  14-Mar-2002  groo branches: 1.27.2;
Fix longstanding misuse of glob(3) and fnmatch(3) in man page search.
glob(3)-special characters are now escaped in the supplied man page names.

Makes ``man ['' work without mysterious quoting.
 1.26  19-Feb-2001  cgd convert to use getprogname()
 1.25  12-Jun-2000  simonb Allow "-s" to specify a section name, ala the SysV man command.
Unlike the SysV man command, this doesn't allow for the -s argument
to be a list.
 1.24  07-Jun-2000  thorpej check_pager() was using an uninitialized variable; fix it.
 1.23  27-May-2000  jdolecek allow to specify relative paths for sections in man.conf - they are used
similarily to _subdir, but only when appropriate
fix -m handling, so that e.g. "man -m . 3 printf" works as it should
add new -S flag, to specify a string the result path has to contain
g/c some unused stuff

Written by Chuck Cranor, with only cosmetic changes & const poisoning by me.
 1.22  09-Jan-2000  tsutsui branches: 1.22.2;
Use uname(3) to determine MACHINE type.
 1.21  02-Nov-1999  lukem revert previous
 1.20  02-Nov-1999  lukem remove superfluous '-' in getopt string
 1.19  22-Jul-1999  kleink branches: 1.19.2;
Try $TMPDIR first, then fall back to _PATH_TMP.
 1.18  22-Jul-1999  itohy A caught signal is blocked in the handler and
must be unblocked to do the default action.
The old code may generate weird exit status
on signals.
 1.17  19-Jun-1999  itohy Remove temp file on SIGPIPE (such as "man sh | head").
 1.16  13-Jun-1999  kleink Fall back to more(1) if PAGER is set but null.
 1.15  06-Nov-1998  christos branches: 1.15.2;
char -> unsigned char
 1.14  08-Oct-1998  wsanchez We can't define MACHINE from a makefile in Rhapsody, because you might be cross
compiling, or building a fat (multi-architecture) binary. Our compiler
defines __ARCHITECTURE__ for this use.
Fixed an off-by-one error that may occasionally cause man to seg fault. Found
by using a special strict malloc() implementation.
 1.13  25-Aug-1998  ross Add { and } to shut up egcs. Reformat the more questionable code.
 1.12  06-Jul-1998  kleink Since GLOB_NOCHECK is not set, explicitly check for a return value of
GLOB_NOMATCH from glob(). Noticed by Juergen Hannken-Illjes.
 1.11  19-Jun-1998  kleink GLOB_QUOTE is dead; per POSIX, backslash quoting of special characters being
enabled is the default behaviour.
 1.10  23-Nov-1997  tv When man was "fixed" to chdir() to the man root as historical man does,
it broke the -M option on relative paths (the chdir works as it should,
but the relative man page path is still used whole in nroff). This
repairs the situation by chopping the full pathname in half--one part
for the chdir, one part for the filename.
 1.9  17-Oct-1997  mikel branches: 1.9.2;
cleanup for WARNS=1
 1.8  10-Sep-1997  mikel resize a pathname buffer to MAXPATHLEN; from Matthias Scheler in PR 4101
 1.7  28-Sep-1995  tls Sync with 4.4BSD-Lite2
 1.6  20-Apr-1995  mycroft Pay attention to the section number, even if MANPATH or -M is specified.
 1.5  16-Jan-1995  mycroft Sync with 4.4-Lite, plus local changes.
 1.4  03-Jun-1994  jtc Fix from Christos Zoulas which makes relative paths in .so lines work when
man pages are formatted.
 1.3  17-Apr-1994  cgd fix from bostic for multiple match problem
 1.2  18-Mar-1994  cgd fix from Keith White <kwhite@csi.UOttawa.CA>, to DTRT when man -w's output
is redirected.
 1.1  21-Dec-1993  cgd branches: 1.1.1;
add man(1) ; part of new man(1) package from Bostic
 1.1.1.2  28-Sep-1995  tls imported from 44lite2
 1.1.1.1  16-Jan-1995  mycroft Import original 4.4-Lite version.
 1.9.2.1  26-Nov-1997  mellon Pull rev 1.10 up from trunk (tv)
 1.15.2.3  30-Apr-2000  he Pull up revisions 1.18-1.22 (requested by kim):
Pull up various changes from the trunk:
o fix signal handlers to avoid obscure exit codes
o clean up after SIGPIPE
o try TMPDIR env variable, fall back to _PATH_TMP
o fall back to more if PAGER is set but null
o use uname(3) to determine MACHINE type
 1.15.2.2  30-Apr-2000  he Pull up revision 1.17 (requested by kim):
Fix a problem where files were not removed on SIGPIPE.
 1.15.2.1  23-Jun-1999  perry pullup 1.15->1.16 (kleink)
 1.19.2.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.22.2.1  23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.27.2.2  03-Nov-2002  he Pull up revision 1.28 (requested by he in ticket #787):
Make these compile again, after the changes in ticket #787.
 1.27.2.1  03-Nov-2002  he Pull up revision 1.29 (requested by thorpej in ticket #787):
Rename man/config.{c,h} to man/manconf.{c,h}, so we do not
have to worry about problems including "config.h" when
building as a host tool.
 1.35.4.1  06-Nov-2007  matt sync with HEAD
 1.36.8.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.37.10.1  21-Apr-2010  matt sync to netbsd-5
 1.37.4.1  08-Oct-2009  sborrill Pull up the following revisions(s) (requested by cegger in ticket #1076):
usr.bin/man/man.1: revision 1.21
usr.bin/man/man.c: revision 1.39

Allow man(1) to accept a pathname to a man file (e.g. man ./man.1)
 1.41.4.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.43.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.43.2.1  17-Apr-2012  yamt sync with head
 1.44.10.1  23-Jul-2013  riastradh sync with HEAD
 1.44.6.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.61.4.1  05-Jan-2016  snj Pull up following revision(s) (requested by mlelstv in ticket #1057):
usr.bin/man/man.c: revision 1.62
For an argument to be interpreted as a local file name, bypassing the
search rules in man.conf or MANPATH, it must begin with "/", "./", or
"../". Simply testing whether it contains "/" is wrong, because it
breaks usage like "man 8 vax/boot".
This reverts revision 1.57 dated 2013-10-06,
"Be more permissive in interpreting man pages as filenames".
 1.64.6.2  11-May-2017  pgoyette Sync with HEAD
 1.64.6.1  02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.66.8.1  25-Jun-2018  pgoyette Sync with HEAD
 1.66.2.1  13-Mar-2022  martin Pull up following revision(s) (requested by gutteridge in ticket #1737):

usr.bin/man/man.c: revision 1.69
usr.bin/man/man.c: revision 1.70
usr.bin/man/man.c: revision 1.72

man.c: fix -m option so it works as documented

Refactoring work in man.c r. 1.40 from twelve years ago introduced a
regression where input from the -m option was appended rather than
prepended to the search paths. Problem reported by C. Chapman on
netbsd-users.

man: fix type mismatch between enum and int (since yesterday)
No binary change.

man: remove unused global variable 'instype' (since yesterday)
No functional change.
 1.67.4.2  13-Mar-2022  martin Pull up following revision(s) (requested by gutteridge in ticket #1433):

usr.bin/man/man.c: revision 1.69
usr.bin/man/man.c: revision 1.70
usr.bin/man/man.c: revision 1.72

man.c: fix -m option so it works as documented

Refactoring work in man.c r. 1.40 from twelve years ago introduced a
regression where input from the -m option was appended rather than
prepended to the search paths. Problem reported by C. Chapman on
netbsd-users.

man: fix type mismatch between enum and int (since yesterday)
No binary change.

man: remove unused global variable 'instype' (since yesterday)
No functional change.
 1.67.4.1  09-Apr-2020  martin Pull up following revision(s) (requested by maya in ticket #824):

usr.bin/man/man.c: revision 1.68

Exit successfully after printing the search path, stop further processing.

Continuing to process had the unintended effect that `man` failed to find
a matching manual page for {EMPTY LIST OF REQUESTED MANUAL PAGES}, and
exited with 1.

Prompted by a fish shell snippet that tried and failed to distinguish between
FreeBSD man (-p takes argument) and NetBSD man (-p no argument) by comparing
`man -p` exit code.

ok riastradh, logix (which also pointed out the manual page SYNOPSIS is
saying man -p should be used this way).
 1.67.2.1  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411

RSS XML Feed