From 046149e0f4e8c94753ca7a2d55a40d954e917fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 1 Apr 2016 02:53:04 +0200 Subject: [PATCH] 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 --- core-modules/000QubesVm.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core-modules/000QubesVm.py b/core-modules/000QubesVm.py index 43b20a73..227ab8ac 100644 --- a/core-modules/000QubesVm.py +++ b/core-modules/000QubesVm.py @@ -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,