[mutter/wip/carlosg/xwayland-on-demand: 7/7] wayland: Implement on-demand start of Xwayland
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/xwayland-on-demand: 7/7] wayland: Implement on-demand start of Xwayland
- Date: Fri, 24 May 2019 21:48:46 +0000 (UTC)
commit 9b3d19a2d35a522e49fbfb0bf2ec234e16978ae8
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri May 24 21:36:50 2019 +0200
wayland: Implement on-demand start of Xwayland
The Xwayland manager now has 4 distinct phases:
- Init and shutdown (Happening together with the compositor itself)
- Start and stop
In these last 2 phases, handle orderly initialization and shutdown
of Xwayland. On initialization We will simply find out what is a
proper display name, and set up the envvar and socket so that clients
think there is a X server.
Whenever we detect data on this socket, we enter the start phase
that will launch Xwayland, and plunge the socket directly to it.
In this phase we now also set up the MetaX11Display.
The stop phase is pretty much the opposite, we will shutdown the
MetaX11Display and all related data, and terminate the Xwayland
process.
The shutdown happens on compositor shutdown and is completely
uninteresting. Some bits there moved into the stop phase as might
happen over and over.
Actual shutdown happens on a timeout whenever the last known
X11 MetaWindow is gone. If no new X clients come back in this
timeout, the X server will eventually shutdown.
This is all controlled by META_DISPLAY_POLICY_ON_DEMAND and
the "autostart-xwayland" experimental setting.
src/core/display.c | 12 ++--
src/core/stack-tracker.c | 7 +-
src/wayland/meta-wayland-private.h | 1 +
src/wayland/meta-xwayland.c | 139 ++++++++++++++++++++++++++++++++-----
4 files changed, 132 insertions(+), 27 deletions(-)
---
diff --git a/src/core/display.c b/src/core/display.c
index d38b2fb3a..6ea456b8e 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -51,6 +51,7 @@
#include "backends/x11/meta-backend-x11.h"
#include "backends/x11/cm/meta-backend-x11-cm.h"
#include "clutter/x11/clutter-x11.h"
+#include "compositor/compositor-private.h"
#include "core/bell.h"
#include "core/boxes-private.h"
#include "core/display-private.h"
@@ -645,12 +646,15 @@ meta_display_init_x11 (MetaDisplay *display,
display->x11_display = x11_display;
g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
- meta_x11_display_create_guard_window (x11_display);
- if (!display->display_opening)
- meta_display_manage_all_windows (display);
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_ON_DEMAND)
+ {
+ meta_x11_display_create_guard_window (x11_display);
+ if (!display->display_opening)
+ meta_display_manage_all_windows (display);
- meta_compositor_redirect_x11_windows (display->compositor);
+ meta_compositor_redirect_x11_windows (display->compositor);
+ }
return TRUE;
}
diff --git a/src/core/stack-tracker.c b/src/core/stack-tracker.c
index 8010e0e8a..765223cef 100644
--- a/src/core/stack-tracker.c
+++ b/src/core/stack-tracker.c
@@ -513,7 +513,7 @@ drop_x11_windows (MetaDisplay *display,
MetaStackTracker *tracker)
{
GArray *new_stack;
- GList *l = NULL;
+ GList *l;
int i;
tracker->xserver_serial = 0;
@@ -531,10 +531,7 @@ drop_x11_windows (MetaDisplay *display,
g_array_unref (tracker->verified_stack);
tracker->verified_stack = new_stack;
- if (tracker->unverified_predictions)
- l = tracker->unverified_predictions->head;
-
- while (l)
+ for (l = tracker->unverified_predictions->head; l; l = l->next)
{
MetaStackOp *op = l->data;
GList *next = l->next;
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index 85b127e75..7bb9a2cd7 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -48,6 +48,7 @@ typedef struct
char *lock_file;
int abstract_fd;
int unix_fd;
+ guint xserver_grace_period_id;
struct wl_display *wayland_display;
struct wl_client *client;
struct wl_resource *xserver_resource;
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index f240d35f4..98a58d9c6 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -33,6 +33,7 @@
#include <sys/un.h>
#include "compositor/meta-surface-actor-wayland.h"
+#include "core/main-private.h"
#include "meta/main.h"
#include "wayland/meta-wayland-actor-surface.h"
@@ -62,6 +63,8 @@ G_DEFINE_TYPE (MetaWaylandSurfaceRoleXWayland,
static int display_number_override = -1;
+static void meta_xwayland_stop_xserver (MetaXWaylandManager *manager);
+
void
meta_xwayland_associate_window_with_surface (MetaWindow *window,
MetaWaylandSurface *surface)
@@ -352,24 +355,33 @@ xserver_died (GObject *source,
g_warning ("Failed to finish waiting for Xwayland: %s", error->message);
}
else if (!g_subprocess_get_successful (proc))
- g_warning ("X Wayland crashed; exiting");
- else
+ g_warning ("X Wayland process exited");
+
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_MANDATORY)
{
- /* For now we simply abort if we see the server exit.
- *
- * In the future X will only be loaded lazily for legacy X support
- * but for now it's a hard requirement. */
- g_warning ("Spurious exit of X Wayland server");
+ meta_exit (META_EXIT_ERROR);
}
+ else if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_ON_DEMAND)
+ {
+ MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
+ MetaDisplay *display = meta_get_display ();
+
+ if (display->x11_display)
+ meta_display_shutdown_x11 (display);
- meta_exit (META_EXIT_ERROR);
+ if (!meta_xwayland_init (&compositor->xwayland_manager,
+ compositor->wayland_display))
+ g_warning ("Failed to init X sockets");
+ }
}
static int
x_io_error (Display *display)
{
g_warning ("Connection to xwayland lost");
- meta_exit (META_EXIT_ERROR);
+
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_MANDATORY)
+ meta_exit (META_EXIT_ERROR);
return 0;
}
@@ -438,6 +450,29 @@ choose_xdisplay (MetaXWaylandManager *manager)
return TRUE;
}
+static gboolean
+reopen_display_sockets (MetaXWaylandManager *manager)
+{
+ gboolean fatal;
+
+ manager->abstract_fd = bind_to_abstract_socket (manager->display_index,
+ &fatal);
+ if (manager->abstract_fd < 0)
+ {
+ g_warning ("Failed to bind abstract socket");
+ return FALSE;
+ }
+
+ manager->unix_fd = bind_to_unix_socket (manager->display_index);
+ if (manager->unix_fd < 0)
+ {
+ close (manager->abstract_fd);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void
xserver_finished_init (MetaXWaylandManager *manager)
{
@@ -455,6 +490,7 @@ on_displayfd_ready (int fd,
gpointer user_data)
{
MetaXWaylandManager *manager = user_data;
+ MetaDisplay *display = meta_get_display ();
/* The server writes its display name to the displayfd
* socket when it's ready. We don't care about the data
@@ -462,6 +498,9 @@ on_displayfd_ready (int fd,
* that means it's ready. */
xserver_finished_init (manager);
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_ON_DEMAND)
+ meta_display_init_x11 (display, NULL);
+
return G_SOURCE_REMOVE;
}
@@ -538,6 +577,31 @@ meta_xwayland_start_xserver (MetaXWaylandManager *manager)
return TRUE;
}
+static gboolean
+xdisplay_connection_activity_cb (gint fd,
+ GIOCondition cond,
+ gpointer user_data)
+{
+ MetaXWaylandManager *manager = user_data;
+
+ if (!meta_xwayland_start_xserver (manager))
+ g_critical ("Could not start Xserver");
+
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean
+shutdown_xwayland_cb (gpointer data)
+{
+ MetaXWaylandManager *manager = data;
+
+ g_debug ("Shutting down Xwayland");
+ manager->xserver_grace_period_id = 0;
+ meta_display_shutdown_x11 (meta_get_display ());
+ meta_xwayland_stop_xserver (manager);
+ return G_SOURCE_REMOVE;
+}
+
static void
window_unmanaged_cb (MetaWindow *window,
MetaXWaylandManager *manager)
@@ -546,6 +610,12 @@ window_unmanaged_cb (MetaWindow *window,
g_signal_handlers_disconnect_by_func (window,
window_unmanaged_cb,
manager);
+ if (!manager->x11_windows)
+ {
+ g_debug ("All X11 windows gone, setting shutdown timeout");
+ manager->xserver_grace_period_id =
+ g_timeout_add_seconds (10, shutdown_xwayland_cb, manager);
+ }
}
static void
@@ -559,18 +629,57 @@ window_created_cb (MetaDisplay *display,
manager->x11_windows = g_list_prepend (manager->x11_windows, window);
g_signal_connect (window, "unmanaged",
G_CALLBACK (window_unmanaged_cb), manager);
+ if (manager->xserver_grace_period_id)
+ {
+ g_source_remove (manager->xserver_grace_period_id);
+ manager->xserver_grace_period_id = 0;
+ }
}
}
+static void
+meta_xwayland_stop_xserver (MetaXWaylandManager *manager)
+{
+ g_subprocess_send_signal (manager->proc, SIGTERM);
+ g_signal_handlers_disconnect_by_func (meta_get_display (),
+ window_created_cb,
+ manager);
+ g_clear_object (&manager->xserver_died_cancellable);
+ g_clear_object (&manager->proc);
+}
+
gboolean
meta_xwayland_init (MetaXWaylandManager *manager,
struct wl_display *wl_display)
{
- if (!choose_xdisplay (manager))
- return FALSE;
+ MetaDisplayPolicy policy;
+
+ if (!manager->display_name)
+ {
+ if (!choose_xdisplay (manager))
+ return FALSE;
+ }
+ else
+ {
+ if (!reopen_display_sockets (manager))
+ return FALSE;
+ }
manager->wayland_display = wl_display;
- return meta_xwayland_start_xserver (manager);
+ policy = meta_get_x11_display_policy ();
+
+ if (policy == META_DISPLAY_POLICY_MANDATORY)
+ {
+ return meta_xwayland_start_xserver (manager);
+ }
+ else if (policy == META_DISPLAY_POLICY_ON_DEMAND)
+ {
+ g_unix_fd_add (manager->abstract_fd, G_IO_IN,
+ xdisplay_connection_activity_cb, manager);
+ return TRUE;
+ }
+
+ return FALSE;
}
static void
@@ -609,13 +718,7 @@ meta_xwayland_shutdown (MetaXWaylandManager *manager)
{
char path[256];
- g_signal_handlers_disconnect_by_func (meta_get_display (),
- window_created_cb,
- manager);
-
g_cancellable_cancel (manager->xserver_died_cancellable);
- g_clear_object (&manager->proc);
- g_clear_object (&manager->xserver_died_cancellable);
snprintf (path, sizeof path, "/tmp/.X11-unix/X%d", manager->display_index);
unlink (path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]