Files
flatpak/tests/make-test-runtime.sh
Valentin David 845a0b3bf7 Use ld.so.cache instead of LD_LIBRARY_PATH (when not building)
Instead of setting LD_LIBRARY_PATH to make the app load the right
libraries we run ldconfig to generate a ld.so.cache that we feed
to the sandbox as /etc/ld.so.cache. The cache itself is generated
by running ldconfig at run time, but for apps we cache the
result in $HOME/.var/app/$APPID/.ld.so/cache based on the
current app/runtime/extensions commit ids.

We also unset LD_LIBRARY_PATH, to ensure any host-side value
does not mess with the sandbox.

The default ld.so.conf we set (if the runtime has none, or an empty
one) is:

 include /run/flatpak/ld.so.conf.d/*.conf
 include /app/etc/ld.so.conf
 /app/lib

Additionally all the extension points that have add_ld_path set gets a
ld.so.conf snippet in /run/flatpak/ld.so.conf.d.

This allows applications and extensions to install their own paths if
needed, and if the runtime wants more location they can install a
custom ld.so.conf that includes the above.

In the flatpak build case we still use LD_LIBRARY_PATH like before,
because there is no good key (like the commit ids) for keeping the
cache up-to-date. Also, the behaviour is different when building an
app for instance. If /app/lib is not in LD_LIBRARY_PATH then the
sandbox-wide /etc/ld.so.cache must be updated for a newly installed
library to work, but the sandbox is not allowed to update
/etc/ld.so.cache.

This code was originally written by Valentin David <valentin.david@gmail.com>
with changes by Alexander Larsson <alexl@redhat.com>.

Closes: #1073
Approved by: alexlarsson
2017-10-04 10:27:14 +00:00

80 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
set -e
DIR=`mktemp -d`
REPONAME=$1
shift
ID=$1
shift
COLLECTION_ID=$1
shift
mkdir ${DIR}/files
mkdir ${DIR}/usr
cat > ${DIR}/metadata <<EOF
[Runtime]
name=${ID}
EOF
cat ${DIR}/metadata
# Add bash and dependencies
mkdir -p ${DIR}/usr/bin
mkdir -p ${DIR}/usr/lib
ln -s ../lib ${DIR}/usr/lib64
ln -s ../lib ${DIR}/usr/lib32
cp `which ldconfig` ${DIR}/usr/bin
T=`mktemp`
for i in $@; do
I=`which $i`
cp $I ${DIR}/usr/bin
ldd $I | sed "s/.* => //" | awk '{ print $1}' | grep ^/ | grep ^/ >> $T
if test $i == python2; then
mkdir -p ${DIR}/usr/lib/python2.7/lib-dynload
# This is a hardcoded minimal set of modules we need in the current tests.
# Pretty hacky stuff. Add modules as needed.
PYDIR=/usr/lib/python2.7
if test -d /usr/lib64/python2.7; then PYDIR=/usr/lib64/python2.7; fi
for py in site os stat posixpath genericpath warnings \
linecache types UserDict abc _abcoll \
_weakrefset copy_reg traceback sysconfig \
re sre_compile sre_parse sre_constants \
_sysconfigdata ; do
cp ${PYDIR}/$py.py ${DIR}/usr/lib/python2.7
done
# These might not exist, depending how Python was configured; and the
# part after ${so} might be "module" or ".x86_64-linux-gnu" or
# something else
for so in _locale strop ; do
cp ${PYDIR}/lib-dynload/${so}*.so ${DIR}/usr/lib/python2.7/lib-dynload || :
done
for plat in $( cd ${PYDIR} && echo plat-* ); do
test -e ${PYDIR}/${plat} || continue
mkdir -p ${DIR}/usr/lib/python2.7/${plat}
cp ${PYDIR}/${plat}/*.py ${DIR}/usr/lib/python2.7/${plat}/
done
fi
done
ln -s bash ${DIR}/usr/bin/sh
for i in `sort -u $T`; do
cp "$i" ${DIR}/usr/lib/
done
# We copy the C.UTF8 locale and call it en_US. Its a bit of a lie, but
# the real en_US locale is often not available, because its in the
# local archive.
mkdir -p ${DIR}/usr/lib/locale/
cp -r /usr/lib/locale/C.* ${DIR}/usr/lib/locale/en_US
if [ x$COLLECTION_ID != x ]; then
collection_args=--collection-id=${COLLECTION_ID}
else
collection_args=
fi
mkdir -p repos
flatpak build-export ${collection_args} --runtime ${GPGARGS-} repos/${REPONAME} ${DIR}
rm -rf ${DIR}