1 |
vapier 14/07/30 08:22:07 |
2 |
|
3 |
Modified: lddtree.py |
4 |
Log: |
5 |
lddtree: do symlink resolution on args on the command line |
6 |
|
7 |
This is needed when given a path which itself is an absolute symlink. If we deref it as-is, we end up poking into / instead of $ROOT. |
8 |
|
9 |
Revision Changes Path |
10 |
1.50 pax-utils/lddtree.py |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.50&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.50&content-type=text/plain |
14 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.49&r2=1.50 |
15 |
|
16 |
Index: lddtree.py |
17 |
=================================================================== |
18 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v |
19 |
retrieving revision 1.49 |
20 |
retrieving revision 1.50 |
21 |
diff -u -r1.49 -r1.50 |
22 |
--- lddtree.py 30 Jul 2014 04:34:09 -0000 1.49 |
23 |
+++ lddtree.py 30 Jul 2014 08:22:07 -0000 1.50 |
24 |
@@ -4,7 +4,7 @@ |
25 |
# Copyright 2012-2014 The Chromium OS Authors |
26 |
# Use of this source code is governed by a BSD-style license (BSD-3) |
27 |
# pylint: disable=C0301 |
28 |
-# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.49 2014/07/30 04:34:09 vapier Exp $ |
29 |
+# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $ |
30 |
|
31 |
# TODO: Handle symlinks. |
32 |
|
33 |
@@ -307,7 +307,7 @@ |
34 |
|
35 |
|
36 |
def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, |
37 |
- debug=False, _first=True, _all_libs={}): |
38 |
+ display=None, debug=False, _first=True, _all_libs={}): |
39 |
"""Parse the ELF dependency tree of the specified file |
40 |
|
41 |
Args: |
42 |
@@ -317,6 +317,7 @@ |
43 |
prefix: The path under |root| to search |
44 |
ldpaths: dict containing library paths to search; should have the keys: |
45 |
conf, env, interp |
46 |
+ display: The path to show rather than |path| |
47 |
debug: Enable debug output |
48 |
_first: Recursive use only; is this the first ELF ? |
49 |
_all_libs: Recursive use only; dict of all libs we've seen |
50 |
@@ -343,7 +344,7 @@ |
51 |
ldpaths = ldpaths.copy() |
52 |
ret = { |
53 |
'interp': None, |
54 |
- 'path': path, |
55 |
+ 'path': path if display is None else display, |
56 |
'needed': [], |
57 |
'rpath': [], |
58 |
'runpath': [], |
59 |
@@ -422,7 +423,8 @@ |
60 |
'needed': [], |
61 |
} |
62 |
if fullpath: |
63 |
- lret = ParseELF(fullpath, root, prefix, ldpaths, debug, False, _all_libs) |
64 |
+ lret = ParseELF(fullpath, root, prefix, ldpaths, debug=debug, |
65 |
+ _first=False, _all_libs=_all_libs) |
66 |
_all_libs[lib]['needed'] = lret['needed'] |
67 |
|
68 |
del elf |
69 |
@@ -435,7 +437,7 @@ |
70 |
|
71 |
|
72 |
def _ShowVersion(_option, _opt, _value, _parser): |
73 |
- d = '$Id: lddtree.py,v 1.49 2014/07/30 04:34:09 vapier Exp $'.split() |
74 |
+ d = '$Id: lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $'.split() |
75 |
print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) |
76 |
sys.exit(0) |
77 |
|
78 |
@@ -684,10 +686,26 @@ |
79 |
|
80 |
matched = False |
81 |
for p in glob.iglob(path): |
82 |
+ # Once we've processed the globs, resolve the symlink. This way you can |
83 |
+ # operate on a path that is an absolute symlink itself. e.g.: |
84 |
+ # $ ln -sf /bin/bash $PWD/root/bin/sh |
85 |
+ # $ lddtree --root $PWD/root /bin/sh |
86 |
+ # First we'd turn /bin/sh into $PWD/root/bin/sh, then we want to resolve |
87 |
+ # the symlink to $PWD/root/bin/bash rather than a plain /bin/bash. |
88 |
+ dbg(options.debug, ' globbed =', p) |
89 |
+ if not path.startswith('/'): |
90 |
+ realpath = os.path.realpath(path) |
91 |
+ elif options.auto_root: |
92 |
+ realpath = readlink(p, options.root, prefixed=True) |
93 |
+ else: |
94 |
+ realpath = path |
95 |
+ if path != realpath: |
96 |
+ dbg(options.debug, ' resolved =', realpath) |
97 |
+ |
98 |
matched = True |
99 |
try: |
100 |
- elf = ParseELF(p, options.root, options.prefix, ldpaths, |
101 |
- debug=options.debug) |
102 |
+ elf = ParseELF(realpath, options.root, options.prefix, ldpaths, |
103 |
+ display=p, debug=options.debug) |
104 |
except exceptions.ELFError as e: |
105 |
if options.skip_non_elfs: |
106 |
continue |