Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 710190 - dev-libs/kpathsea installs symlinks that point outside of EPREFIX
Summary: dev-libs/kpathsea installs symlinks that point outside of EPREFIX
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Alexis Ballier
URL:
Whiteboard:
Keywords: PATCH, PullRequest
Depends on:
Blocks:
 
Reported: 2020-02-19 16:31 UTC by Nick Bowler
Modified: 2020-07-25 05:06 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
proposed patch (kpathsea-fix.patch,885 bytes, patch)
2020-02-19 16:31 UTC, Nick Bowler
Details | Diff
patch proposal (kpathsea.patch,586 bytes, patch)
2020-04-21 12:45 UTC, Olivier Huber
Details | Diff
patch proposal (kpathsea.patch,590 bytes, patch)
2020-04-21 16:28 UTC, Olivier Huber
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Bowler 2020-02-19 16:31:25 UTC
Created attachment 614496 [details, diff]
proposed patch

In a prefixed installation, the dev-libs/kpathsea ebuild installs the following two symlinks:

  [prefix]/usr/share/texmf-dist/web2c/texmf.cnf -> /etc/texmf/web2c/texmf.cnf
  [prefix]/usr/share/texmf-dist/web2c/fmtutil.cnf -> /etc/texmf/web2c/fmtutil.cnf

These point to the system /etc, not the prefix etc where these files actually live, and this leads to the following error in pkg_postinst:

  Generating ls-R files
  warning: kpathsea: configuration file texmf.cnf not found in these directories: /SCRATCH/gentoo/usr/bin:/SCRATCH/gentoo/usr/bin/share/texmf-local/web2c:/SCRATCH/gentoo/usr/bin/share/texmf-dist/web2c:/SCRATCH/gentoo/usr/bin/share/texmf/web2c:/SCRATCH/gentoo/usr/bin/texmf-local/web2c:/SCRATCH/gentoo/usr/bin/texmf-dist/web2c:/SCRATCH/gentoo/usr/bin/texmf/web2c:/SCRATCH/gentoo/usr:/SCRATCH/gentoo/usr/share/texmf-local/web2c:/SCRATCH/gentoo/usr/share/texmf-dist/web2c:/SCRATCH/gentoo/usr/share/texmf/web2c:/SCRATCH/gentoo/usr/texmf-local/web2c:/SCRATCH/gentoo/usr/texmf-dist/web2c:/SCRATCH/gentoo/usr/texmf/web2c:/SCRATCH/texmf-local/web2c:/SCRATCH/gentoo:/SCRATCH/gentoo/share/texmf-local/web2c:/SCRATCH/gentoo/share/texmf-dist/web2c:/SCRATCH/gentoo/share/texmf/web2c:/SCRATCH/gentoo/texmf-local/web2c:/SCRATCH/gentoo/texmf-dist/web2c:/SCRATCH/gentoo/texmf/web2c.
  dirname: missing operand
  Try 'dirname --help' for more information.

While this doesn't prevent kpathsea installation, this problem is fatal when installing later texlive packages, e.g., dev-texlive/texlive-basic:

   * Building format texmf-dist/fmtutil/format.texlive-basic.cnf
  [snip identical kpathsea error]
  /SCRATCH/gentoo/usr/bin/fmtutil: kpsewhich -var-value=TEXMFROOT failed, aborting early.
  BEGIN failed--compilation aborted at /SCRATCH/gentoo/usr/bin/fmtutil line 25.
   * ERROR: dev-texlive/texlive-basic-2019-r1::gentoo failed (compile phase):
   *   failed to build format texmf-dist/fmtutil/format.texlive-basic.cnf

This is all fixed by ensuring that these two symlinks point within the prefix, for example the attached patch changes the ebuild to create relative symlinks which do not suffer from this problem.

Portage 2.3.89 (python 3.6.10-final-0, default/linux/amd64/17.0/no-multilib/prefix/kernel-3.2+, gcc-9.2.0, glibc-2.30-r4, 3.10.0-957.5.1.el7.x86_64 x86_64)
=================================================================
System uname: Linux-3.10.0-957.5.1.el7.x86_64-x86_64-Intel-R-_Core-TM-_i7-4790_CPU_@_3.60GHz-with-centos-7.6.1810-Core
KiB Mem:    16204384 total,   5566992 free
KiB Swap:   32605180 total,  32603380 free
Timestamp of repository gentoo: Tue, 18 Feb 2020 00:45:01 +0000
sh bash 5.0_p16
ld GNU ld (Gentoo 2.34 p1) 2.34.0
app-shells/bash:          5.0_p16::gentoo
dev-lang/perl:            5.30.1::gentoo
dev-lang/python:          2.7.17-r1::gentoo, 3.6.10::gentoo, 3.7.6::gentoo, 3.8.1::gentoo
dev-util/cmake:           3.16.4::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/sandbox:         2.18::gentoo
sys-devel/autoconf:       2.69-r5::gentoo
sys-devel/automake:       1.16.1-r2::gentoo
sys-devel/binutils:       2.34::gentoo
sys-devel/gcc:            9.2.0-r4::gentoo
sys-devel/gcc-config:     2.2.1::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.5::gentoo (virtual/os-headers)
sys-libs/glibc:           2.30-r4::gentoo
Repositories:

gentoo
    location: /SCRATCH/gentoo/srv/repos/gentoo
    sync-type: webrsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-webrsync-verify-signature: true

gentoo-draconx
    location: /SCRATCH/gentoo/srv/repos/gentoo-draconx
    masters: gentoo

gentoo-fixes
    location: /SCRATCH/gentoo/srv/repos/gentoo-fixes
    masters: gentoo

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="@FREE"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=haswell -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/SCRATCH/gentoo/etc /etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/SCRATCH/gentoo/etc/env.d /SCRATCH/gentoo/etc/gentoo-release /etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -march=haswell -pipe"
DISTDIR="/SCRATCH/gentoo/var/cache/distfiles"
ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles force-prefix ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sfperms strict unknown-features-warn unmerge-logs unmerge-orphans unprivileged xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_CA.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j5"
PKGDIR="/SCRATCH/gentoo/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/SCRATCH/gentoo/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/SCRATCH/gentoo/var/tmp"
USE="X acl amd64 berkdb bzip2 cli crypt cxx dri fontconfig fortran gdbm iconv icu ipv6 jpeg libtirpc ncurses nls nptl openmp pam pcre perl png prefix readline seccomp split-usr ssl svg tcpd truetype unicode xattr xft xinerama zlib" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_6" PYTHON_TARGETS="python2_7 python3_6" RUBY_TARGETS="ruby24 ruby25" USERLAND="GNU" VIDEO_CARDS="amdgpu fbdev intel nouveau radeon radeonsi vesa dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Olivier Huber 2020-04-21 12:20:28 UTC
This also broke my tex install. The mistake is in the relative path specification.

In the ebuild we have
dosym /../../../../etc/texmf/web2c/fmtutil.cnf ${TEXMF_PATH}/web2c/fmtutil.cnf

but

$ realpath /../../.. /..
/

Before this change https://github.com/gentoo/portage/pull/499/files it may have worked by accident, with EPREFIX being implicitly applied. Now this is gone and must be explicit.

Relative path seems too error-prone here. I proposed a patch with a absolute path. I am not sure whether EROOT or EPREFIX has to be used.
Comment 2 Olivier Huber 2020-04-21 12:45:16 UTC
Created attachment 634014 [details, diff]
patch proposal

For dev-libs/kpathsea-6.3.2_p20200406
Comment 3 Nick Bowler 2020-04-21 15:00:00 UTC
(In reply to Olivier Huber from comment #1)
> This also broke my tex install. The mistake is in the relative path
> specification.
> 
> In the ebuild we have
> dosym /../../../../etc/texmf/web2c/fmtutil.cnf
> ${TEXMF_PATH}/web2c/fmtutil.cnf

I'm confused.  What broke your tex install?  Are you talking about the
ebuild with my proposed patch applied?

My patch doesn't (or well, it shouldn't) put a slash in front like that.
The symroot variable is calculated simply by counting slashes in
$TEXMF_PATH/web2c and the expected result is symroot=../../../../

so

  dosym ${symroot}etc/texmf/web2c/fmtutil.cnf ${TEXMF_PATH}/web2c/fmtutil.cnf

should expand to

  dosym ../../../../etc/texmf/web2c/fmtutil.cnf /usr/share/texmf-dist/web2c/fmtutil.cnf

which looks fine...

> Before this change https://github.com/gentoo/portage/pull/499/files it may
> have worked by accident, with EPREFIX being implicitly applied. Now this is
> gone and must be explicit.
> 
> Relative path seems too error-prone here. I proposed a patch with a absolute
> path. I am not sure whether EROOT or EPREFIX has to be used.

It has to be EPREFIX.

EROOT includes the ROOT setting which is essentially only valid during the
execution of the ebuild itself... but the symlinks persist long after that.

When the installed package is executed the files will have been moved to
the target (or chroot will have been performed, or whatever) and ROOT-based
absolute symlinks will all be broken.

This is the main reason why relative symlinks are almost always preferable to
absolute ones, because they remain valid independent of ROOT, EPREFIX,
and the exact location of where the filesystems are mounted.
Comment 4 Olivier Huber 2020-04-21 16:26:50 UTC
The bug (dev-libs/kpathsea installs symlinks that point outside of EPREFIX) broke my tex install, not your patch :) Thanks for the input on EROOT vs EPREFIX
The ebuild excerpt I put is from the file kpathsea-6.3.2_p20200406.ebuild, whereas your patch is for kpathsea-6.3.1_p20190410.ebuild

The relative path approach seems less robust to me than the absolute path approach: this may be nonstandard, but due to space restriction, my texmf-dist folder is on a different filesystem than the rest of my prefix install. Since I have no root access, this means that it is a symlink in ${EPREFIX}/usr/share. The relative path then fails to reach the desired file in ${EPREFIX}/etc and ends up pointing to an non-existing file.

Furthermore, this issue is present since portage no longer preprends EPREFIX to the first argument of dosym, see the link in my previous comment. Before that January commit, the previous behaviour was to also use the absolute path. There was a long discussion about this in https://bugs.gentoo.org/show_bug.cgi?id=615594 where the point of not breaking existing prefix install was raised. And I would say that this point is important. If the system behaved in a certain way, one should not modify it without good reasons.

The relative path approach would allow to move the prefix install around, however I don't think this is of interest since the interpreter for all ELF binaries is set to an absolute path. Then there are also all the shebang. Hence, one has already to do a lot of work on a prefix install to move it around.
Comment 5 Olivier Huber 2020-04-21 16:28:34 UTC
Created attachment 634020 [details, diff]
patch proposal

Updated patch: uses EPREFIX rather than EROOT
Comment 6 Nick Bowler 2020-04-21 16:58:53 UTC
(In reply to Olivier Huber from comment #4)
> The relative path approach seems less robust to me than the absolute path
> approach: this may be nonstandard, but due to space restriction, my
> texmf-dist folder is on a different filesystem than the rest of my prefix
> install. Since I have no root access, this means that it is a symlink in
> ${EPREFIX}/usr/share.

I see.  If any of the components of ${EPREFIX}/usr/share/texmf-dist/web2c
are symlinks (excluding EPREFIX itself) then it will be problematic creating
a relative symlink in there.  (The situation cannot be detected until the
package is merged so it would be tricky to solve in an ebuild).

Such a scenario doesn't arise in "normal" installations: the user must
manually modify the installation directories to create symlinks.

To be honest if you are manually mucking with install directories like
this I'd suggest just manually create these two symlinks exactly how
you want them and then throw them in INSTALL_MASK so they don't get
overwritten later.

> The relative path approach would allow to move the prefix install around,
> however I don't think this is of interest since the interpreter for all ELF
> binaries is set to an absolute path.

It's not so much about moving files around and expecting things to run
successfully in the new location.

Cnsider running emerge with ROOT=/some/where -- an absolute symlinks will
be installed as /some/where/usr/share/texmf-dist/web2c/fmtutil.cnf ->
/etc/texmf/web2c/fmtutil.cnf

The symlink is "correct" in some sense but note that the target is outside
of the ROOT: it will not be valid until the files are actually moved to
the target system.  This is not a problem by itself but it will be if any
packages depend on the symlink being valid at build or merge time.

I have no idea whether this matters in this specific instance (I have never
tried TeX ebuilds with ROOT).
Comment 7 Nick Bowler 2020-06-04 14:44:05 UTC
It seems like an attempt was made to fix this in kpathsea-6.3.2_p20200406 but it is still busted.  The ebuild now reads:

  dosym /../../../../etc/texmf/web2c/fmtutil.cnf ${TEXMF_PATH}/web2c/fmtutil.cnf

which is just weird.  That creates exactly the same symlink as the previous ebuild, just the filename now is spelled with four redundant ../ components...
Comment 8 Mark J. Olah 2020-07-25 00:04:54 UTC
The current dev-libs/kpathsea-6.3.2_p20200406 is still broken for prefix installs.  The following works for me both with a prefix and without.

dosym /../../../../etc/texmf/web2c/fmtutil.cnf ${TEXMF_PATH}/web2c/fmtutil.cnf

->

dosym ../../../../etc/texmf/web2c/fmtutil.cnf ${TEXMF_PATH}/web2c/fmtutil.cnf


See: https://github.com/gentoo/gentoo/pull/16808
Comment 9 Larry the Git Cow gentoo-dev 2020-07-25 05:06:19 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=bad1a3b37da5a0cc59f3910e175d9446c8a29cdc

commit bad1a3b37da5a0cc59f3910e175d9446c8a29cdc
Author:     Mark J. Olah <markjolah@users.noreply.github.com>
AuthorDate: 2020-07-24 23:57:20 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2020-07-25 05:05:35 +0000

    dev-libs/kpathsea: Fix symlink targets
    
    Closes: https://bugs.gentoo.org/710190
    Signed-off-by: Mark J. Olah <mjo@cs.unm.edu>
    Closes: https://github.com/gentoo/gentoo/pull/16808
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-libs/kpathsea/kpathsea-6.3.2_p20200406.ebuild | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)