Skip to content

Commit

Permalink
tools/qvm-run: exit the shell after executing requested command
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
marmarek committed May 18, 2017
1 parent d0bcd3e commit 8686ef4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions qubesadmin/tests/tools/qvm_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_000_run_single(self):
'stderr': subprocess.DEVNULL,
'user': None,
}),
('test-vm', 'qubes.VMShell', b'command\n')
('test-vm', 'qubes.VMShell', b'command; exit\n')
])
self.assertAllCalled()

Expand All @@ -77,15 +77,15 @@ def test_001_run_multiple(self):
'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,
'stdout': subprocess.DEVNULL,
'stderr': subprocess.DEVNULL,
'user': None,
}),
('test-vm2', 'qubes.VMShell', b'command\n')
('test-vm2', 'qubes.VMShell', b'command; exit\n')
])
self.assertAllCalled()

Expand All @@ -111,7 +111,7 @@ def test_002_passio(self):
'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()

Expand Down Expand Up @@ -139,7 +139,7 @@ def test_002_color_output(self):
'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()
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_003_no_color_output(self):
'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()
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_004_no_filter_esc(self):
'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()
Expand All @@ -227,7 +227,7 @@ def test_005_localcmd(self):
'stderr': None,
'user': None,
}),
('test-vm', 'qubes.VMShell', b'command\n')
('test-vm', 'qubes.VMShell', b'command; exit\n')
])
self.assertAllCalled()

Expand Down Expand Up @@ -259,6 +259,6 @@ def test_006_run_single_with_gui(self):
'stderr': subprocess.DEVNULL,
'user': None,
}),
('test-vm', 'qubes.VMShell', b'command\n')
('test-vm', 'qubes.VMShell', b'command; exit\n')
])
self.assertAllCalled()
3 changes: 2 additions & 1 deletion qubesadmin/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def prepare_input_for_vmshell(command, input=None):
''' # 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.
Expand Down

0 comments on commit 8686ef4

Please sign in to comment.