Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: lddtree.sh
Date: Sun, 04 Nov 2012 07:21:00
Message-Id: 20121104072043.949D9215F3@flycatcher.gentoo.org
1 vapier 12/11/04 07:20:43
2
3 Modified: lddtree.sh
4 Log:
5 lddtree: add ROOT support #430366 by Richard Yao
6
7 Revision Changes Path
8 1.12 pax-utils/lddtree.sh
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.sh?rev=1.12&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.sh?rev=1.12&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.sh?r1=1.11&r2=1.12
13
14 Index: lddtree.sh
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.sh,v
17 retrieving revision 1.11
18 retrieving revision 1.12
19 diff -u -r1.11 -r1.12
20 --- lddtree.sh 3 Nov 2012 00:06:10 -0000 1.11
21 +++ lddtree.sh 4 Nov 2012 07:20:43 -0000 1.12
22 @@ -1,8 +1,12 @@
23 #!/bin/bash
24 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.sh,v 1.11 2012/11/03 00:06:10 vapier Exp $
25 +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.sh,v 1.12 2012/11/04 07:20:43 vapier Exp $
26
27 argv0=${0##*/}
28
29 +: ${ROOT:=/}
30 +[[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
31 +[[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}"
32 +
33 usage() {
34 cat <<-EOF
35 Display ELF dependencies as a tree
36 @@ -10,9 +14,10 @@
37 Usage: ${argv0} [options] <ELF file[s]>
38
39 Options:
40 - -a Show all duplicated dependencies
41 - -x Run with debugging
42 - -h Show this help output
43 + -a Show all duplicated dependencies
44 + -x Run with debugging
45 + -h Show this help output
46 + -R <root> Use this ROOT filesystem tree
47 EOF
48 exit ${1:-0}
49 }
50 @@ -27,7 +32,7 @@
51 scanelf -BF '#F%a %M %D %I' "$1"
52 }
53
54 -lib_paths_fallback="/lib* /usr/lib* /usr/local/lib*"
55 +lib_paths_fallback="${ROOT}lib* ${ROOT}usr/lib* ${ROOT}usr/local/lib*"
56 c_ldso_paths_loaded='false'
57 find_elf() {
58 _find_elf=''
59 @@ -73,7 +78,7 @@
60 if ! ${c_ldso_paths_loaded} ; then
61 c_ldso_paths_loaded='true'
62 c_ldso_paths=()
63 - if [[ -r /etc/ld.so.conf ]] ; then
64 + if [[ -r ${ROOT}etc/ld.so.conf ]] ; then
65 read_ldso_conf() {
66 local line p
67 for p ; do
68 @@ -84,14 +89,14 @@
69 case ${line} in
70 "#"*) ;;
71 "include "*) read_ldso_conf ${line#* } ;;
72 - *) c_ldso_paths+=( "${line}" ) ;;
73 + *) c_ldso_paths+=( "${ROOT}${line#/}" ) ;;
74 esac
75 done <"${p}"
76 done
77 }
78 # the 'include' command is relative
79 - pushd /etc >/dev/null
80 - read_ldso_conf /etc/ld.so.conf
81 + pushd "${ROOT}"etc >/dev/null
82 + read_ldso_conf "${ROOT}"etc/ld.so.conf
83 popd >/dev/null
84 fi
85 fi
86 @@ -122,12 +127,15 @@
87 if [[ ${indent} -eq 0 ]] ; then
88 elf_specs=$(elf_specs "${resolved}")
89 interp=$(scanelf -qF '#F%i' "${resolved}")
90 + [[ -n ${interp} ]] && interp="${ROOT}${interp#/}"
91
92 printf " (interpreter => ${interp:-none})"
93 if [[ -r ${interp} ]] ; then
94 # Extract the default lib paths out of the ldso.
95 - lib_paths_ldso=$(strings "${interp}" | grep '^/.*lib')
96 - lib_paths_ldso=${lib_paths_ldso//:/ }
97 + lib_paths_ldso=$(
98 + strings "${interp}" | \
99 + sed -nr -e "/^\/.*lib/{s|^/?|${ROOT}|;s|/$||;s|/?:/?|\n${ROOT}|g;p}"
100 + )
101 fi
102 interp=${interp##*/}
103 fi
104 @@ -158,11 +166,12 @@
105 SHOW_ALL=false
106 SET_X=false
107
108 -while getopts hax OPT ; do
109 +while getopts haxR: OPT ; do
110 case ${OPT} in
111 a) SHOW_ALL=true;;
112 x) SET_X=true;;
113 h) usage;;
114 + R) ROOT="${OPTARG%/}/";;
115 ?) usage 1;;
116 esac
117 done