Browse Source

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
Marek Marczykowski-Górecki 8 years ago
parent
commit
046149e0f4
1 changed files with 7 additions and 3 deletions
  1. 7 3
      core-modules/000QubesVm.py

+ 7 - 3
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,