core: fix vm.run_service 'wait' argument handling

1. wait=False isn't supportet together with localcmd (explicit, or
   implicit via 'input') - qrexec-client refuses such combination
2. When using localcmd, qrexec-client exists as soon as the local command
   terminates, not necessary remote. This may not be desired effect when
   used with wait=True (the default), so do not use localcmd in such a
   case

Found while debugging tests for qubes.USBAttach/qubes.USBDetach - with
wait=True broken, there were a lot of race conditions.

Related to QubesOS/qubes-issues#531
This commit is contained in:
Marek Marczykowski-Górecki 2016-04-01 02:53:04 +02:00
parent 47e81a525e
commit 046149e0f4
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -1676,13 +1676,17 @@ class QubesVm(object):
if bool(input) + bool(passio_popen) + bool(localcmd) > 1:
raise ValueError("'input', 'passio_popen', 'localcmd' cannot be "
"used together")
if not wait and (localcmd or input):
raise ValueError("Cannot use wait=False with input or "
"localcmd specified")
if localcmd:
return self.run("QUBESRPC %s %s" % (service, source),
localcmd=localcmd, user=user, wait=wait, gui=gui)
elif input:
return self.run("QUBESRPC %s %s" % (service, source),
localcmd="echo %s" % input, user=user, wait=wait,
gui=gui)
p = self.run("QUBESRPC %s %s" % (service, source),
user=user, wait=wait, gui=gui, passio_popen=True)
p.communicate(input)
return p.returncode
else:
return self.run("QUBESRPC %s %s" % (service, source),
passio_popen=passio_popen, user=user, wait=wait,