poky/scripts/qemuimage-testlib-pythonhelper
Richard Purdie c2835acc80 qemuimage-testlib-pythonhelper: Make the process detection more strict
Old versions of ldd (2.11) as run on some of the autobuilders end up running
commands like "LD_xxxx qemu-system-xxx" which this process detection code
would pick up and result in the wrong PID for qemu.

This changes the code to check for "192.168" in the command so we know
we're getting the correct one. This is less than ideal however we're
running out of options and resolves false negatives we see on the
autobuilder.

(From OE-Core rev: 7b43151bb073f1f6f1fa5a31447b742127060909)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-04-29 14:45:07 +01:00

1.9 KiB
Executable File

#!/usr/bin/env python

import optparse import subprocess import sys import os

parser = optparse.OptionParser( usage = """ %prog [options] """)

parser.add_option("-q", "--findqemu", help = "find a qemu beneath the process ", action="store", dest="findqemu")

options, args = parser.parse_args(sys.argv)

if options.findqemu: # # Walk the process tree from the process specified looking for a qemu-system. Return its pid. # ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] processes = ps.split('\n') nfields = len(processes[0].split()) - 1 pids = {} commands = {} for row in processes[1:]: data = row.split(None, nfields) if len(data) != 3: continue if data[1] not in pids: pids[data[1]] = [] pids[data[1]].append(data[0]) commands[data[0]] = data[2]

if options.findqemu not in pids:
    sys.stderr.write("No children found matching %s" % options.findqemu)
    sys.exit(1)

parents = []
newparents = pids[options.findqemu]
while newparents:
    next = []
    for p in newparents:
        if p in pids:
            for n in pids[p]:
                if n not in parents and n not in next:
                    next.append(n)

        if p not in parents:
            parents.append(p)
    newparents = next
#print "Children matching %s:" % str(parents)
for p in parents:
    # Need to be careful here since runqemu-internal runs "ldd qemu-system-xxxx"
    # Also, old versions of ldd (2.11) run "LD_XXXX qemu-system-xxxx"
    basecmd = commands[p].split()[0]
    basecmd = os.path.basename(basecmd)
    if "qemu-system" in basecmd and "192.168" in commands[p]:
        print p
        sys.exit(0)
sys.exit(1)

else: parser.print_help()