dom0/appmenus-receive: use common API for running commands in VM

Do not use qrexec_client directly.
This commit is contained in:
Marek Marczykowski 2012-11-13 04:03:30 +01:00
parent f47f8e7c8f
commit 69b803f286

View File

@ -47,11 +47,11 @@ fields_regexp = {
"Exec": re.compile(r"^[a-zA-Z0-9%>/:.= -]*$"), "Exec": re.compile(r"^[a-zA-Z0-9%>/:.= -]*$"),
} }
def get_appmenus(xid): def get_appmenus(vm):
global appmenus_line_count global appmenus_line_count
global appmenus_line_size global appmenus_line_size
untrusted_appmenulist = [] untrusted_appmenulist = []
if xid == -1: if vm is None:
while appmenus_line_count > 0: while appmenus_line_count > 0:
untrusted_line = sys.stdin.readline(appmenus_line_size) untrusted_line = sys.stdin.readline(appmenus_line_size)
if untrusted_line == "": if untrusted_line == "":
@ -61,8 +61,7 @@ def get_appmenus(xid):
if appmenus_line_count == 0: if appmenus_line_count == 0:
raise QubesException("Line count limit exceeded") raise QubesException("Line count limit exceeded")
else: else:
p = subprocess.Popen ([qrexec_client_path, '-d', str(xid), p = vm.run('DEFAULT:QUBESRPC qubes.GetAppmenus dom0', passio_popen=True)
'user:QUBESRPC qubes.GetAppmenus dom0'], stdout=subprocess.PIPE)
while appmenus_line_count > 0: while appmenus_line_count > 0:
untrusted_line = p.stdout.readline(appmenus_line_size) untrusted_line = p.stdout.readline(appmenus_line_size)
if untrusted_line == "": if untrusted_line == "":
@ -184,14 +183,10 @@ def main():
new_appmenus = {} new_appmenus = {}
if env_vmname is None: if env_vmname is None:
# Get appmenus from VM new_appmenus = get_appmenus(vm)
xid = vm.get_xid()
assert xid > 0
new_appmenus = get_appmenus(xid)
else: else:
options.verbose = False options.verbose = False
new_appmenus = get_appmenus(-1) new_appmenus = get_appmenus(None)
if len(new_appmenus) == 0: if len(new_appmenus) == 0:
print >>sys.stderr, "ERROR: No appmenus received, terminating" print >>sys.stderr, "ERROR: No appmenus received, terminating"