diff --git a/ci/requirements.txt b/ci/requirements.txt index d95bff4..99d1a07 100644 --- a/ci/requirements.txt +++ b/ci/requirements.txt @@ -8,3 +8,4 @@ python-daemon mock lxml PyYAML +xcffib diff --git a/qubesadmin/tools/qvm_start_gui.py b/qubesadmin/tools/qvm_start_gui.py index e47d8f2..86ae27e 100644 --- a/qubesadmin/tools/qvm_start_gui.py +++ b/qubesadmin/tools/qvm_start_gui.py @@ -23,10 +23,10 @@ import os import signal import subprocess - import asyncio - import re +import xcffib +import xcffib.xproto # pylint: disable=unused-import import daemon.pidfile import qubesadmin @@ -346,6 +346,14 @@ class GUILauncher(object): events.add_handler('connection-established', self.on_connection_established) +def x_reader(conn, callback): + '''Try reading something from X connection to check if it's still alive. + In case it isn't, call *callback*. + ''' + try: + conn.poll_for_event() + except xcffib.ConnectionException: + callback() if 'XDG_RUNTIME_DIR' in os.environ: pidfile_path = os.path.join(os.environ['XDG_RUNTIME_DIR'], @@ -394,10 +402,15 @@ def main(args=None): loop.add_signal_handler(signal.SIGHUP, launcher.send_monitor_layout_all) + conn = xcffib.connect() + x_fd = conn.get_file_descriptor() + loop.add_reader(x_fd, x_reader, conn, events_listener.cancel) + try: loop.run_until_complete(events_listener) except asyncio.CancelledError: pass + loop.remove_reader(x_fd) loop.stop() loop.run_forever() loop.close() diff --git a/rpm_spec/qubes-core-admin-client.spec b/rpm_spec/qubes-core-admin-client.spec index 578d5bb..e2dfc25 100644 --- a/rpm_spec/qubes-core-admin-client.spec +++ b/rpm_spec/qubes-core-admin-client.spec @@ -46,6 +46,7 @@ Summary: Python34 module qubesadmin Requires: python-daemon Requires: python34-docutils Requires: python34-lxml +Requires: python34-xcffib Conflicts: qubes-manager < 4.0.6 %description -n python34-qubesadmin @@ -56,6 +57,7 @@ Summary: Python3 module qubesadmin Requires: python3-daemon Requires: python3-docutils Requires: python3-lxml +Requires: python3-xcffib Conflicts: qubes-manager < 4.0.6 %description -n python3-qubesadmin