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: if bool(input) + bool(passio_popen) + bool(localcmd) > 1:
raise ValueError("'input', 'passio_popen', 'localcmd' cannot be " raise ValueError("'input', 'passio_popen', 'localcmd' cannot be "
"used together") "used together")
if not wait and (localcmd or input):
raise ValueError("Cannot use wait=False with input or "
"localcmd specified")
if localcmd: if localcmd:
return self.run("QUBESRPC %s %s" % (service, source), return self.run("QUBESRPC %s %s" % (service, source),
localcmd=localcmd, user=user, wait=wait, gui=gui) localcmd=localcmd, user=user, wait=wait, gui=gui)
elif input: elif input:
return self.run("QUBESRPC %s %s" % (service, source), p = self.run("QUBESRPC %s %s" % (service, source),
localcmd="echo %s" % input, user=user, wait=wait, user=user, wait=wait, gui=gui, passio_popen=True)
gui=gui) p.communicate(input)
return p.returncode
else: else:
return self.run("QUBESRPC %s %s" % (service, source), return self.run("QUBESRPC %s %s" % (service, source),
passio_popen=passio_popen, user=user, wait=wait, passio_popen=passio_popen, user=user, wait=wait,