Skip to content

Commit

Permalink
Update ld-precache part
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Llewellyn <daniel@bowlhat.net>
  • Loading branch information
Daniel Llewellyn committed May 15, 2020
1 parent d6dd589 commit d7622dc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
7 changes: 7 additions & 0 deletions docs/lib/linker-cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,12 @@ prefixed with ``$SNAP/``:
:start-after: ### START environ
:end-before: ### END environ

Add the layout definition for the ``ld.so.cache`` file:

.. literalinclude:: ../../examples/linker-cache/snapcraft.yaml
:language: yaml
:start-after: ### START layout
:end-before: ### END layout

This library expects you to have added
the :ref:`Extensible Hooks <extensible_hooks>` customisations, too.
6 changes: 6 additions & 0 deletions examples/linker-cache/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ parts:
environment:
FINAL_BINARY: $SNAP/usr/bin/my-app
### END environ

### START layout
layout:
/etc/ld.so.cache:
bind-file: $SNAP_DATA/etc/ld.so.cache
### END layout
21 changes: 12 additions & 9 deletions snapcraft-assets/ld-precache/bin/build-ld-cache
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#!/bin/bash -ex

# copying the conf dir from real /etc into $SNAP_DATA
mkdir -p "$SNAP_DATA/etc/ld.so.conf.d"
cp -r /etc/ld.so.conf.d/* "$SNAP_DATA/etc/ld.so.conf.d"
cp /etc/ld.so.conf "$SNAP_DATA/etc/ld.so.conf"
#!/bin/bash -e

# delete empty entries in the LD_LIBRARY_PATH
# i.e. change "/a/b/c:/1/2/3::/other" into "/a/b/c:/1/2/3:/other"
# if we don't do this, then ldconfig gets confused with "" as arguments of dirs
# to add to the cache
LD_LIBRARY_PATH="${LD_LIBRARY_PATH//::/:}"
# Remove leading empty element if it exists
LD_LIBRARY_PATH="${LD_LIBRARY_PATH#:}"
# Remove trailing empty element if it exists
LD_LIBRARY_PATH="${LD_LIBRARY_PATH%:}"

# run ldconfig on our LD_LIBRARY_PATH lib dirs
IFS=':' read -ra PATHS <<< "$LD_LIBRARY_PATH"
# The fake-etc directory is to allow ldconfig to unlink the
# ld.so.cache file without breaking the bind-file layout on
# the real ld.so.cache file.
mkdir -p "$SNAP_DATA/fake-etc"
ldconfig -v -C "$SNAP_DATA/fake-etc/ld.so.cache" -f "$SNAP_DATA/etc/ld.so.conf" "${PATHS[@]}"

# install the new ld.so.cache to the global location by just copying it
cp "$SNAP_DATA/fake-etc/ld.so.cache" "$SNAP_DATA/etc/ld.so.cache"
# install the new ld.so.cache to the global location by
# copying it. We must not unlink the global file or the snap
# 'layout' configuration will break.
cp "$SNAP_DATA/fake-etc/ld.so.cache" "$SNAP_DATA/etc/ld.so.cache"
6 changes: 1 addition & 5 deletions snapcraft-assets/ld-precache/bin/check-ld-cache
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ else
# TODO: make this less of a hack?
if ldd "$FINAL_BINARY" | grep "=> not found" | grep -q "=> not found"; then
# regenerate the cache first
LD_LIBRARY_PATH=$ORIGINAL_LD_LIBRARY_PATH
LD_LIBRARY_PATH="$ORIGINAL_LD_LIBRARY_PATH"
export LD_LIBRARY_PATH
# "$SNAP/bin/build-ld-cache"
# # unset to continue executing the next command in the chain
# LD_LIBRARY_PATH=""
# export LD_LIBRARY_PATH
fi
fi

Expand Down

0 comments on commit d7622dc

Please sign in to comment.