Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5bf3d6db10
Fetching contributors…

Cannot retrieve contributors at this time

executable file 97 lines (74 sloc) 2.303 kb
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
#!/usr/bin/env python

import os, sys, argparse
from subprocess import PIPE, Popen

CACHEFILE = os.path.join(os.getenv('HOME'), '.cache/solinks')

SEARCHPATHS = [
    '/lib/',
    '/lib32/',
    '/usr/lib/',
    '/usr/lib32/',
    '/usr/local/lib/',
    '/usr/local/lib32/',
    '/bin/',
    '/sbin/',
    '/usr/bin/',
    '/usr/sbin/'
    '/opt/',
]

def stdout_of(cmd):
    return Popen(cmd,
            stdout=PIPE,
            stderr=PIPE).communicate()[0].decode('utf-8')

def has_prefix(i):
    for path in SEARCHPATHS:
        if i.startswith(path):
            return True

    return False

def write_solinks(cachefile, pkg, files):
    out = stdout_of(['objdump', '-p'] + files)

    links = []

    for line in out.split('\n'):
        try:
            section, solink = line.strip().split(' ', 1)
        except:
            continue

        if section == "NEEDED":
            links.append(solink.strip())

    for link in sorted(set(links)):
        print("{}\t{}".format(pkg, link), file=cachefile)

def sogrep(search):
    with open(CACHEFILE) as solinks:
        for line in solinks:
            pkgname, soname = line.rstrip().split('\t')
            if soname.startswith(search):
                print(pkgname)

def createlinks():
    pkgs = {}
    filelist = stdout_of(['pacman', '-Ql'])

    for f in filelist.split('\n'):
        if not f:
            break
        pkg, fname = f.split(' ', 1)

        if fname.endswith('/') or not has_prefix(fname) or os.path.islink(fname):
            continue

        if not pkgs.get(pkg):
            pkgs[pkg] = []
        pkgs[pkg].append(fname)

    with open(CACHEFILE, "w") as cachefile:
        for k, v in sorted(pkgs.items()):
            write_solinks(cachefile, k, v)

def main():
    parser = argparse.ArgumentParser(description='find soname revdeps')

    parser.add_argument('-c', '--create', action='store_true', dest='create', default=False,
            help='rebuild soname cache')

    parser.add_argument('soname', nargs='?', help='soname to search')

    opts = parser.parse_args()

    if opts.create:
        createlinks()
    else:
        if not opts.soname:
            print("error: no soname specified", file=sys.stderr)
            sys.exit(1)
        sogrep(opts.soname)

if __name__ == '__main__':
    main()
Something went wrong with that request. Please try again.