summaryrefslogtreecommitdiffstats
path: root/main/lddtree/0001-lddtree-print-resolved-interp-symlinks.patch
blob: 81d4951a42ea093d1dd367857b275fe5ab913c6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
From 0f78645bb0941639bbc11bf047326fb9d7f9292a Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
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