xwayland: Set libX11 error handlers to no-ops before terminating

We might not be the only entity holding on to the X11 GdkDisplay,
meaning the X11 connection will stay alive indefinitely, e.g. if the gjs
context has some reference to it.

Avoid running into issues due to X11 connection errors by setting the
libX11 handlers to no-ops, so when we are terminating; that means the
GDK X11 connection can stay "alive" until its too late, and we'll just
silently ignore any connection errors that may happen due to the
lingering GDK display reference.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1822>
This commit is contained in:
Jonas Ådahl 2021-04-20 19:00:14 +02:00 committed by Marge Bot
parent c4a73e7950
commit b71f52ff32

View File

@ -607,6 +607,12 @@ x_io_error (Display *display)
return 0;
}
static int
x_io_error_noop (Display *display)
{
return 0;
}
#ifdef HAVE_XSETIOERROREXITHANDLER
static void
x_io_error_exit (Display *display,
@ -619,6 +625,12 @@ x_io_error_exit (Display *display,
manager->xserver_grace_period_id =
g_idle_add (shutdown_xwayland_cb, manager);
}
static void
x_io_error_exit_noop (Display *display,
void *data)
{
}
#endif
void
@ -1264,10 +1276,19 @@ meta_xwayland_connection_release (MetaXWaylandConnection *connection)
void
meta_xwayland_shutdown (MetaXWaylandManager *manager)
{
#ifdef HAVE_XSETIOERROREXITHANDLER
MetaX11Display *x11_display = meta_get_display ()->x11_display;
#endif
char path[256];
g_cancellable_cancel (manager->xserver_died_cancellable);
XSetIOErrorHandler (x_io_error_noop);
#ifdef HAVE_XSETIOERROREXITHANDLER
XSetIOErrorExitHandler (meta_x11_display_get_xdisplay (x11_display),
x_io_error_exit_noop, NULL);
#endif
snprintf (path, sizeof path, "%s%d", X11_TMP_UNIX_PATH,
manager->public_connection.display_index);
unlink (path);