commit:     8209b9955e06f2238c7c4d2732652e7fb0f3c977
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Tue May 27 23:46:25 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Tue May 27 23:46:25 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=8209b995

misc/ldd: correct logic for ldpaths()

---
 misc/ldd/ldd.py | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/misc/ldd/ldd.py b/misc/ldd/ldd.py
index 4d6f500..c1bcc19 100755
--- a/misc/ldd/ldd.py
+++ b/misc/ldd/ldd.py
@@ -53,15 +53,17 @@ def ldpaths(ld_so_conf='/etc/ld.so.conf'):
 
     paths = []
     include_globs = []
-    for l in lines:
-        if l == '':
+    for i in range(0,len(lines)):
+        if lines[i] == '':
             continue
-        if l == 'include':
-            f = lines[lines.index(l) + 1]
+        if lines[i] == 'include':
+            f = lines[i + 1]
             include_globs.append(f)
             continue
-        if l not in include_globs:
-            paths.append(os.path.realpath(l))
+        if lines[i] not in include_globs:
+            real_path = os.path.realpath(lines[i])
+            if os.path.exists(real_path):
+                paths.append(real_path)
 
     include_files = []
     for g in include_globs:
@@ -69,13 +71,17 @@ def ldpaths(ld_so_conf='/etc/ld.so.conf'):
     for c in include_files:
         paths = paths + ldpaths(os.path.realpath(c))
 
-    return list(set(paths))
+    paths = list(set(paths))
+    paths.sort()
+    return paths
 
 
 def dynamic_dt_needed_paths( dt_needed, eclass, paths):
     for n in dt_needed:
         for p in paths:
-            print('%s' % p + '/' + n)
+            lib = p + os.sep + n
+            if os.path.exists(lib):
+                print('%s' % lib)
     return
 
 SCRIPT_DESCRIPTION = 'Print shared library dependencies'
@@ -98,8 +104,6 @@ def main():
         sys.exit(0)
 
     paths = ldpaths()
-    print(paths)
-    sys.exit(0)
 
     for f in args:
         with open(f, 'rb') as file:

Reply via email to