aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2018-09-07 16:28:32 -0700
committerMike Frysinger <vapier@gentoo.org>2023-12-22 00:31:16 -0500
commit00c695d6152bb8f2e7a288a5c019986ed3ee9495 (patch)
treeab898b8c0b654038936c7e3fae9ae77dac0976a1
parentlddtree: keep relativeness of invoked program in elf wrapper (diff)
downloadpax-utils-00c695d6152bb8f2e7a288a5c019986ed3ee9495.tar.gz
pax-utils-00c695d6152bb8f2e7a288a5c019986ed3ee9495.tar.bz2
pax-utils-00c695d6152bb8f2e7a288a5c019986ed3ee9495.zip
lddtree: use readlink -f for absolute links
Commit b97eba7fb2c0a3c5ad9e3831c6f87dca1fde59c5 causes problems when using lddtree with symlinks containing absolute paths, such as the crosvm guest tools, which install these links: /usr/bin/sommelier -> /etc/alternatives/sommelier -> /opt/google/cros-containers/bin/sommelier (where the final sommelier is the lddtree-generated script). In this case, $base resolved by the lddtree script would be '/usr/bin//etc/alternatives/sommelier', which is incorrect. Replace the dirname/readlink combination with readlink -f when the symlink is absolute in order to fully resolve the symlink, while keeping the relative path when the script is invoked through a relative path. Bug: https://crbug.com/882055 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Signed-off-by: Mike Frysinger <vapier@chromium.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-xlddtree.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/lddtree.py b/lddtree.py
index bbf9df9..8184e8f 100755
--- a/lddtree.py
+++ b/lddtree.py
@@ -187,7 +187,13 @@ def GenerateLdsoWrapper(
# remove absolute paths from build outputs and enables directory independent
# cache sharing in distributed build systems.
wrapper = """#!/bin/sh
-if ! base=$(dirname "$0")/$(readlink "$0" 2>/dev/null); then
+if base=$(readlink "$0" 2>/dev/null); then
+ # If $0 is an abspath symlink, fully resolve the target.
+ case ${base} in
+ /*) base=$(readlink -f "$0" 2>/dev/null);;
+ *) base=$(dirname "$0")/${base};;
+ esac
+else
case $0 in
/*) base=$0;;
*) base=${PWD:-`pwd`}/$0;;