[mutter] xwayland: Mark our X11 connection terminatable



commit 42855b69e7b37e229e6a8a6c4fb129c94141e899
Author: Olivier Fourdan <ofourdan redhat com>
Date:   Wed Mar 17 15:44:45 2021 +0100

    xwayland: Mark our X11 connection terminatable
    
    The connection to the Xserver for the X11 window manager part of mutter
    even on Wayland may prevent the Xserver from shutting down.
    
    Currently, what mutter does is to check the X11 clients still connected
    to Xwayland using the XRes extension, with a list of X11 clients that
    can be safely ignored (typically the GNOME XSettings daemon, the IBus
    daemon, pulseaudio and even mutter window manager itself).
    
    When there is just those known clients remaining, mutter would kill
    Xwayland automatically.
    
    But that's racy, because between the time mutter checks with Xwayland
    the remaining clients and the time it actually kills the process, a new
    X11 client might have come along and won't be able to connect to
    Xwayland that mutter is just about to kill.
    
    Because of that, the feature “autoclose-xwayland” is marked as an
    experimental feature in mutter and not enabled by default.
    
    Thankfully, the Xserver has all it takes to manage that already, and
    is even capable of terminating itself once all X11 clients are gone (the
    -terminate option on the command line).
    
    With XFixes version 6, the X11 clients can declare themselves
    "terminatable", so that the Xserver could simply ignore those X11
    clients when checking the remaining clients and terminate itself
    automatically.
    
    Use that mechanism to declare mutter's own connection to the Xserver as
    "terminatable" when Xwayland is started on demand so that it won't hold
    Xwayland alive for the sole purpose of mutter itself.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1794>

 config.h.meson              |  3 +++
 meson.build                 | 13 ++++++++++++-
 src/wayland/meta-xwayland.c |  3 +++
 3 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/config.h.meson b/config.h.meson
index b7ca736df7..4939d2a730 100644
--- a/config.h.meson
+++ b/config.h.meson
@@ -91,3 +91,6 @@
 
 /* List of executable names to ignore when terminating Xwayland */
 #mesondefine XWAYLAND_IGNORE_EXECUTABLES
+
+/* Whether the Xwayland -terminate supports a delay */
+#mesondefine HAVE_XWAYLAND_TERMINATE_DELAY
diff --git a/meson.build b/meson.build
index 4334b8e6a3..8f615bd666 100644
--- a/meson.build
+++ b/meson.build
@@ -28,7 +28,7 @@ json_glib_req = '>= 0.12.0'
 upower_glib_req = '>= 0.99.0'
 xcomposite_req = '>= 0.4'
 xkbcommon_req = '>= 0.4.3'
-xfixes_req = '>= 3'
+xfixes_req = '>= 6'
 xi_req = '>= 1.7.4'
 xrandr_req = '>= 1.5.0'
 libstartup_notification_req = '>= 0.7'
@@ -457,6 +457,7 @@ endif
 
 have_xwayland_initfd = false
 have_xwayland_listenfd = false
+have_xwayland_terminate_delay = false
 if have_wayland
   xwayland_dep = dependency('xwayland', required: false)
 
@@ -509,6 +510,15 @@ if have_wayland
   if (have_xwayland_listenfd)
     cdata.set('HAVE_XWAYLAND_LISTENFD', 1)
   endif
+
+  # For Xwayland -listenfd usage
+  if xwayland_dep.found()
+    have_xwayland_terminate_delay = xwayland_dep.get_pkgconfig_variable('have_terminate_delay') == 'true'
+  endif
+
+  if (have_xwayland_terminate_delay)
+    cdata.set('HAVE_XWAYLAND_TERMINATE_DELAY', 1)
+  endif
 endif
 
 have_xsetioerrorexithandler = false
@@ -593,6 +603,7 @@ summary('Profiler', have_profiler, section: 'Options')
 summary('Xwayland initfd', have_xwayland_initfd, section: 'Options')
 summary('Xwayland listenfd', have_xwayland_listenfd, section: 'Options')
 summary('Safe X11 I/O errors', have_xsetioerrorexithandler, section: 'Options')
+summary('Xwayland terminate delay', have_xwayland_terminate_delay, section: 'Options')
 
 summary('Enabled', have_tests, section: 'Tests')
 summary('Core tests', have_core_tests, section: 'Tests')
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index 77fb366ea1..5613f386d1 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -40,6 +40,7 @@
 #endif
 #include <unistd.h>
 #include <X11/extensions/Xrandr.h>
+#include <X11/extensions/Xfixes.h>
 #include <X11/Xauth.h>
 #include <X11/Xlib-xcb.h>
 
@@ -1305,6 +1306,8 @@ meta_xwayland_setup_xdisplay (MetaXWaylandManager *manager,
   XSetIOErrorExitHandler (xdisplay, x_io_error_exit, manager);
 #endif
 
+  XFixesSetClientDisconnectMode (xdisplay, XFixesClientDisconnectFlagTerminate);
+
   add_local_user_to_xhost (xdisplay);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]