[tex-k] SELFAUTOLOC fails: /path//[../other/file] -> /path/other/file

Jouni K Seppanen jkseppan@james.hut.fi
07 Mar 2002 19:15:26 +0200


Hello,

I think I have discovered a bug in kpathsea/progname.c. The version is
the one in TeX Live 6 (kpathsea version 3.3.3.1), and I have repeated
the problem on web2c-7.3.3 that I downloaded from
<ftp://ftp.tug.org/tex/web2c/> (kpathsea version 3.3.3). The platform
is Linux (Red Hat 7.1, kernel 2.4.17), but the same thing seems to
happen on Irix (6.5.15m) as well.

I have installed TeX Live using GNU Stow¹, which basically puts each
package in a separate subdirectory hierarchy and then creates link
farms under .../bin and other directories. For example, ``latex'' is
(in our case) in /r/stow/texlive-6/bin/latex, and /r/bin/latex is a
symbolic link to ../stow/texlive-6/bin/latex. TeX Live uses the
SELFAUTOLOC facility to find configuration files. This works fine,
except that one user said latex couldn't find latex.fmt. I isolated
the problem to the component ``/r/bin/'' in the user's path; when it
was replaced by ``/r/bin'', everything worked.

I compiled kpsewhich with ll_verbose set to 1 in progname.c, and
installed it under /tmp/testing, with /tmp/testing/linkbin having a
link named ``kpsewhich'' to ``../bin/kpsewhich''. Now I get the
following results:

~ >/tmp/testing/linkbin//kpsewhich texmf.cnf
/tmp/testing/linkbin//[kpsewhich] -> /tmp/testing/linkbin//[../bin/kpsewhich]
                                  == /tmp/testing/linkbin/bin/kpsewhich
lstat(/tmp/testing/linkbin/bin) failed ...
/tmp/testing/linkbin/bin: No such file or directory

~ >/tmp/testing/linkbin/kpsewhich texmf.cnf
/tmp/testing/linkbin/[kpsewhich] -> /tmp/testing/linkbin/[../bin/kpsewhich]
                                 == /tmp/testing/bin/kpsewhich

It seems that when argv[0] contains a double slash and a file name
that is actually a symlink beginning with ``..'', kpathsea takes the
``..'' to cancel an empty directory name between the two slashes,
while Linux considers multiple slashes to form only one separator. 

I guess the easy workaround is to tell users to avoid slashes at the
end of path components, but it would be nice to have this fixed, as
most other programs seem to work also in this case.

¹  http://www.gnu.org/software/stow/

-- 
Jouni K Seppänen