Hi Todd, hi Jan,
Todd C. Miller wrote on Wed, May 06, 2015 at 09:42:41AM -0600:
> On Wed, 06 May 2015 17:23:20 +0200, Jan Stary wrote:
>> This is the latest amd64 snapshot.
>> Is seems that there is a subtle bug in man(1).
>>
>> If I augment my man path with -m ~/man,
>> as I do with alias man='man -m ~/man',
>> man(1) does not find the system manpages, saying
>>
>> man: No entry for ls in the manual.
>>
>> but it does find and display those in ~/man correctly.
>> This happens if /etc/man.conf does not exist.
Precise problem report, thanks.
> It also works if the MANPATH environment variable is set.
Not quite true; if MANPATH starts or ends with ":" or contains "::"
and man.conf does not exist or contains no manpath or _whatdb
directive, it fails to combine MANPATH with the default path and
instead uses MANPATH only.
> The problem appears to be this:
>
> if (conf->manpath.sz == 0)
> manpath_parseline(&conf->manpath, manpath_default, 0);
True.
> If -m is specified, conf->manpath.sz will be 1, not 0.
Not necessarily, if the -m argument contains at least one colon,
conf->manpath.sz will be greater than 1.
> An ugly way to fix this is:
>
> if (conf->manpath.sz == !!auxp)
> manpath_parseline(&conf->manpath, manpath_default, 0);
That's an incomplete fix for two reasons: It works neither with a
colon in -m nor with a leading, trailing, or double colon in MANPATH.
Are you OK with the following patch?
It uses the default path if and only if /etc/man.conf (or the -C
argument) does not exist or does not contain any manpath or
_whatdb directive.
Yours,
Ingo
Index: manpath.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/manpath.c,v
retrieving revision 1.14
diff -u -p -r1.14 manpath.c
--- manpath.c 27 Mar 2015 17:36:56 -0000 1.14
+++ manpath.c 6 May 2015 17:30:35 -0000
@@ -39,7 +39,6 @@ void
manconf_parse(struct manconf *conf, const char *file,
char *defp, char *auxp)
{
- char manpath_default[] = MANPATH_DEFAULT;
char *insert;
/* Always prepend -m. */
@@ -59,8 +58,6 @@ manconf_parse(struct manconf *conf, cons
/* No MANPATH; use man.conf(5) only. */
if (NULL == defp || '\0' == defp[0]) {
manconf_file(conf, file);
- if (conf->manpath.sz == 0)
- manpath_parseline(&conf->manpath, manpath_default, 0);
return;
}
@@ -164,13 +161,14 @@ static void
manconf_file(struct manconf *conf, const char *file)
{
const char *const toks[] = { "manpath", "output", "_whatdb" };
+ char manpath_default[] = MANPATH_DEFAULT;
FILE *stream;
char *cp, *ep;
size_t len, tok;
if ((stream = fopen(file, "r")) == NULL)
- return;
+ goto out;
while ((cp = fgetln(stream, &len)) != NULL) {
ep = cp + len;
@@ -204,6 +202,7 @@ manconf_file(struct manconf *conf, const
/* FALLTHROUGH */
case 0: /* manpath */
manpath_add(&conf->manpath, cp, 0);
+ *manpath_default = '\0';
break;
case 1: /* output */
manconf_output(&conf->output, cp);
@@ -212,8 +211,11 @@ manconf_file(struct manconf *conf, const
break;
}
}
-
fclose(stream);
+
+out:
+ if (*manpath_default != '\0')
+ manpath_parseline(&conf->manpath, manpath_default, 0);
}
void