(Boeing r1784,1785)

implement local flag when receiving Execute Message, for running host commands
added checkforkernelmodule helper
This commit is contained in:
ahrenholz 2013-10-22 14:32:42 +00:00
parent d676a9fd59
commit 0fc51e38bf
2 changed files with 51 additions and 8 deletions

View file

@ -100,6 +100,22 @@ def mutedetach(*args, **kwds):
kwds["stderr"] = subprocess.STDOUT
return subprocess.Popen(*args, **kwds).pid
def cmdresult(args):
''' Execute a command on the host and return a tuple containing the
exit status and result string. stderr output
is folded into the stdout result string.
'''
cmdid = subprocess.Popen(args, stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
cmdid.stdin.close()
result = cmdid.stdout.read()
result += cmdid.stderr.read()
cmdid.stdout.close()
cmdid.stderr.close()
status = cmdid.wait()
return (status, result)
def hexdump(s, bytes_per_word = 2, words_per_line = 8):
dump = ""
count = 0
@ -243,3 +259,16 @@ def readfileintodict(filename, d):
d[key] = value.strip()
except ValueError:
pass
def checkforkernelmodule(name):
''' Return a string if a Linux kernel module is loaded, None otherwise.
The string is the line from /proc/modules containing the module name,
memory size (bytes), number of loaded instances, dependencies, state,
and kernel memory offset.
'''
with open('/proc/modules', 'r') as f:
for line in f:
if line[:len(name)] == name:
return line
return None