From 0f78645bb0941639bbc11bf047326fb9d7f9292a Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 2 Apr 2014 08:54:00 +0200 Subject: [PATCH] lddtree: print resolved interp symlinks --- lddtree.sh | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lddtree.sh b/lddtree.sh index cb9db42..28c06d0 100644 --- a/lddtree.sh +++ b/lddtree.sh @@ -140,6 +140,28 @@ list_existing_file() { fi } +# echo all intermediate symlinks and return the resolved path in +# global variable _resolv_links +resolv_links() { + _resolv_links="$1" + local oldpwd="$PWD" + list_existing_file "${_resolv_links}" + cd "${_resolv_links%/*}" + while [ -L "$_resolv_links" ]; do + _resolv_links=$(readlink "$_resolv_links") + case "$_resolv_links" in + /*) _resolv_links="${ROOT}${_resolv_links#/}" + cd "${_resolv_links%/*}" + ;; + */*) cd "${_resolv_links%/*}" + ;; + esac + _resolv_links=$(pwd -P)/${_resolv_links##*/} + list_existing_file "${_resolv_links}" + done + cd "$oldpwd" +} + show_elf() { local elf=$1 indent=$2 parent_elfs=$3 local rlib lib libs @@ -157,30 +179,10 @@ show_elf() { esac parent_elfs="${parent_elfs},${elf}" if ${LIST} ; then - list_existing_file "${resolved:-$1}" + resolv_links "${resolved:-$1}" else printf "${resolved:-not found}" fi - local oldpwd="$PWD" - cd "${resolved%/*}" - while [ -L "$resolved" ]; do - resolved=$(readlink "$resolved") - case "$resolved" in - /*) resolved="${ROOT}${resolved#/}" - cd "${resolved%/*}" - ;; - */*) cd "${resolved%/*}" - ;; - esac - resolved=$(pwd -P)/${resolved##*/} - - if ${LIST} ; then - list_existing_file "${resolved:-$1}" - else - printf "${resolved:-not found}" - fi - done - cd "$oldpwd" if [ ${indent} -eq 0 ] ; then elf_specs=$(elf_specs "${resolved}") interp=$(scanelf -qF '#F%i' "${resolved}") @@ -189,7 +191,7 @@ show_elf() { [ -n "${interp}" ] && interp="${ROOT}${interp#/}" if ${LIST} ; then - [ -n "${interp}" ] && echo "${interp}" + [ -n "${interp}" ] && resolv_links "${interp}" else printf " (interpreter => ${interp:-none})" fi -- 1.9.0