From 8686ef423a6a9839a3f2a434ae13c59b5f5e3051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 18 May 2017 09:54:26 +0200 Subject: [PATCH] tools/qvm-run: exit the shell after executing requested command Since we use qubes.VMShell service now and send requested command on its stdin, we need to terminate that shell after requested command - otherwise the service will not terminate automatically waiting for further input (next commands). --- qubesadmin/tests/tools/qvm_run.py | 18 +++++++++--------- qubesadmin/vm/__init__.py | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/qubesadmin/tests/tools/qvm_run.py b/qubesadmin/tests/tools/qvm_run.py index 0508ed2..eff6feb 100644 --- a/qubesadmin/tests/tools/qvm_run.py +++ b/qubesadmin/tests/tools/qvm_run.py @@ -53,7 +53,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': subprocess.DEVNULL, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\n') + ('test-vm', 'qubes.VMShell', b'command; exit\n') ]) self.assertAllCalled() @@ -77,7 +77,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': subprocess.DEVNULL, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\n'), + ('test-vm', 'qubes.VMShell', b'command; exit\n'), ('test-vm2', 'qubes.VMShell', { 'filter_esc': True, 'localcmd': None, @@ -85,7 +85,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': subprocess.DEVNULL, 'user': None, }), - ('test-vm2', 'qubes.VMShell', b'command\n') + ('test-vm2', 'qubes.VMShell', b'command; exit\n') ]) self.assertAllCalled() @@ -111,7 +111,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': None, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\nsome-data\n') + ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n') ]) self.assertAllCalled() @@ -139,7 +139,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': None, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\nsome-data\n') + ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n') ]) self.assertEqual(stdout.getvalue(), '\033[0;31m\033[0m') stdout.close() @@ -170,7 +170,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': None, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\nsome-data\n') + ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n') ]) self.assertEqual(stdout.getvalue(), '') stdout.close() @@ -201,7 +201,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': None, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\nsome-data\n') + ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n') ]) self.assertEqual(stdout.getvalue(), '') stdout.close() @@ -227,7 +227,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': None, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\n') + ('test-vm', 'qubes.VMShell', b'command; exit\n') ]) self.assertAllCalled() @@ -259,6 +259,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): 'stderr': subprocess.DEVNULL, 'user': None, }), - ('test-vm', 'qubes.VMShell', b'command\n') + ('test-vm', 'qubes.VMShell', b'command; exit\n') ]) self.assertAllCalled() diff --git a/qubesadmin/vm/__init__.py b/qubesadmin/vm/__init__.py index 2c9d85e..aac6c3f 100644 --- a/qubesadmin/vm/__init__.py +++ b/qubesadmin/vm/__init__.py @@ -268,7 +268,8 @@ class QubesVM(qubesadmin.base.PropertyHolder): ''' # pylint: disable=redefined-builtin if input is None: input = b'' - return b''.join((command.rstrip('\n').encode('utf-8'), b'\n', input)) + return b''.join((command.rstrip('\n').encode('utf-8'), + b'; exit\n', input)) def run(self, command, input=None, **kwargs): '''Run a shell command inside the domain using qubes.VMShell qrexec.