summaryrefslogtreecommitdiffstats
path: root/main/pax-utils/lddtree-sh.patch
blob: 6967df81c6b42ebf68c9468a1bfac56e2b1f2e2f (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
--- ./lddtree.sh.orig	2014-03-18 13:38:57.284756931 +0100
+++ ./lddtree.sh	2014-03-18 13:22:47.296407170 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 # Copyright 2007-2013 Gentoo Foundation
 # Copyright 2007-2013 Mike Frysinger <vapier@gentoo.org>
 # Distributed under the terms of the GNU General Public License v2
@@ -7,8 +7,9 @@
 argv0=${0##*/}
 
 : ${ROOT:=/}
-[[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
-[[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}"
+
+[ "${ROOT}" = "${ROOT%/}" ] && ROOT="${ROOT}/"
+[ "${ROOT}" = "${ROOT#/}" ] && ROOT="${PWD}/${ROOT}"
 
 usage() {
 	cat <<-EOF
@@ -54,7 +55,7 @@
 	_find_elf=''
 
 	local elf=$1 needed_by=$2
-	if [[ ${elf} == */* ]] && [[ -e ${elf} ]] ; then
+	if [ "${elf}" != "${elf##*/}" ] && [ -e "${elf}" ] ; then
 		_find_elf=${elf}
 		return 0
 	else
@@ -63,8 +64,8 @@
 			local path pe
 			for path ; do
 				pe="${path%/}/${elf#/}"
-				if [[ -e ${pe} ]] ; then
-					if [[ $(elf_specs "${pe}") == "${elf_specs}" ]] ; then
+				if [ -e "${pe}" ] ; then
+					if [ "$(elf_specs "${pe}")" = "${elf_specs}" ] ; then
 						_find_elf=${pe}
 						return 0
 					fi
@@ -73,52 +74,53 @@
 			return 1
 		}
 
-		if [[ ${c_last_needed_by} != ${needed_by} ]] ; then
-			c_last_needed_by=${needed_by}
+		if [ "${c_last_needed_by}" != "${needed_by}" ] ; then
+			c_last_needed_by="${needed_by}"
 			c_last_needed_by_rpaths=$(scanelf -qF '#F%r' "${needed_by}" | \
 				sed -e 's|:| |g' -e "s:[$]ORIGIN:${needed_by%/*}:")
 		fi
 		check_paths "${elf}" ${c_last_needed_by_rpaths} && return 0
 
-		if [[ -n ${LD_LIBRARY_PATH} ]] ; then
+		if [ -n "${LD_LIBRARY_PATH}" ] ; then
 			# Need to handle empty paths as $PWD,
 			# and handle spaces in between the colons
 			local p path=${LD_LIBRARY_PATH}
 			while : ; do
 				p=${path%%:*}
 				check_paths "${elf}" "${p:-${PWD}}" && return 0
-				[[ ${path} == *:* ]] || break
+				[ "${path}" = "${path#*:}" ] && break
 				path=${path#*:}
 			done
 		fi
 
 		if ! ${c_ldso_paths_loaded} ; then
 			c_ldso_paths_loaded='true'
-			c_ldso_paths=()
-			if [[ -r ${ROOT}etc/ld.so.conf ]] ; then
+			c_ldso_paths=
+			if [ -r ${ROOT}etc/ld.so.conf ] ; then
 				read_ldso_conf() {
 					local line p
 					for p ; do
 						# if the glob didnt match anything #360041,
 						# or the files arent readable, skip it
-						[[ -r ${p} ]] || continue
+						[ -r "${p}" ] || continue
 						while read line ; do
 							case ${line} in
 								"#"*) ;;
 								"include "*) read_ldso_conf ${line#* } ;;
-								*) c_ldso_paths+=( "${ROOT}${line#/}" ) ;;
+								*) c_ldso_paths="$c_ldso_paths:${ROOT}${line#/}";;
 							esac
 						done <"${p}"
 					done
 				}
 				# the 'include' command is relative
-				pushd "${ROOT}"etc >/dev/null
+				local _oldpwd="$PWD"
+				cd "$ROOT"etc >/dev/null
 				read_ldso_conf "${ROOT}"etc/ld.so.conf
-				popd >/dev/null
+				cd "$_oldpwd"
 			fi
 		fi
-		if [[ ${#c_ldso_paths[@]} -gt 0 ]] ; then
-			check_paths "${elf}" "${c_ldso_paths[@]}" && return 0
+		if [ -n "${c_ldso_paths}" ] ; then
+			check_paths "${elf}" ${c_ldso_paths//:/ } && return 0
 		fi
 
 		check_paths "${elf}" ${lib_paths_ldso:-${lib_paths_fallback}} && return 0
@@ -135,27 +137,29 @@
 	elf=${elf##*/}
 
 	${LIST} || printf "%${indent}s%s => " "" "${elf}"
-	if [[ ,${parent_elfs}, == *,${elf},* ]] ; then
+	case ",${parent_elfs}," in
+	*,${elf},*)
 		${LIST} || printf "!!! circular loop !!!\n" ""
 		return
-	fi
+		;;
+	esac
 	parent_elfs="${parent_elfs},${elf}"
 	if ${LIST} ; then
 		echo "${resolved:-$1}"
 	else
 		printf "${resolved:-not found}"
 	fi
-	if [[ ${indent} -eq 0 ]] ; then
+	if [ ${indent} -eq 0 ] ; then
 		elf_specs=$(elf_specs "${resolved}")
 		interp=$(scanelf -qF '#F%i' "${resolved}")
-		[[ -n ${interp} ]] && interp="${ROOT}${interp#/}"
+		[ -n "${interp}" ] && interp="${ROOT}${interp#/}"
 
 		if ${LIST} ; then
-			[[ -n ${interp} ]] && echo "${interp}"
+			[ -n "${interp}" ] && echo "${interp}"
 		else
 			printf " (interpreter => ${interp:-none})"
 		fi
-		if [[ -r ${interp} ]] ; then
+		if [ -r "${interp}" ] ; then
 			# Extract the default lib paths out of the ldso.
 			lib_paths_ldso=$(
 				strings "${interp}" | \
@@ -166,7 +170,7 @@
 	fi
 	${LIST} || printf "\n"
 
-	[[ -z ${resolved} ]] && return
+	[ -z "${resolved}" ] && return
 
 	libs=$(scanelf -qF '#F%n' "${resolved}")
 
@@ -178,16 +182,15 @@
 
 	for lib in ${libs//,/ } ; do
 		lib=${lib##*/}
-		[[ ,${my_allhits}, == *,${lib},* ]] && continue
+		case ",${my_allhits}," in
+			*,${lib},*) continue;;
+		esac
 		find_elf "${lib}" "${resolved}"
 		rlib=${_find_elf}
 		show_elf "${rlib:-${lib}}" $((indent + 4)) "${parent_elfs}"
 	done
 }
 
-# XXX: internal hack
-if [[ $1 != "/../..source.lddtree" ]] ; then
-
 SHOW_ALL=false
 SET_X=false
 LIST=false
@@ -210,8 +213,8 @@
 	?) usage 1;;
 	esac
 done
-shift $((OPTIND - 1))
-[[ -z $1 ]] && usage 1
+shift $(( $OPTIND - 1))
+[ -z "$1" ] && usage 1
 
 ${SET_X} && set -x
 
@@ -219,21 +222,20 @@
 for elf ; do
 	unset lib_paths_ldso
 	unset c_last_needed_by
-	if ${AUTO_ROOT} && [[ ${elf} == /* ]] ; then
+	if ${AUTO_ROOT} && [ -z "${elf##/*}" ] ; then
 		elf="${ROOT}${elf#/}"
 	fi
-	if [[ ! -e ${elf} ]] ; then
+	if [ ! -e "${elf}" ] ; then
 		error "${elf}: file does not exist"
-	elif [[ ! -r ${elf} ]] ; then
+	elif [ ! -r "${elf}" ] ; then
 		error "${elf}: file is not readable"
-	elif [[ -d ${elf} ]] ; then
+	elif [ -d "${elf}" ] ; then
 		error "${elf}: is a directory"
 	else
 		allhits=""
-		[[ ${elf} != */* ]] && elf="./${elf}"
+		[ "${elf##*/*}" = "${elf}" ] && elf="./${elf}"
 		show_elf "${elf}" 0 ""
 	fi
 done
 exit ${ret}
 
-fi