ソースを参照

tools: terminate qvm-start-gui when X server is terminated

qvm-start-gui lifecycle should be bound to X server lifecycle. It should
be restarted when user logoff and login again, at least to start
gui-daemons again.
Do that by opening a connection to X server and reacting to breaking
that socket.

Fixes QubesOS/qubes-issues#3147
Marek Marczykowski-Górecki 6 年 前
コミット
9bf404f7bf

+ 1 - 0
ci/requirements.txt

@@ -8,3 +8,4 @@ python-daemon
 mock
 lxml
 PyYAML
+xcffib

+ 15 - 2
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()

+ 2 - 0
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