|
|
180070 |
From d366b2bc4e89ed5807f0221afc25e66cb3d289ed Mon Sep 17 00:00:00 2001
|
|
|
180070 |
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
|
|
|
180070 |
Date: Wed, 9 Dec 2020 11:23:37 +0100
|
|
|
180070 |
Subject: [PATCH 1/2] xwayland: Don't spew warnings when looking for X11
|
|
|
180070 |
displays
|
|
|
180070 |
|
|
|
180070 |
It's not important, so only show it when doing MUTTER_DEBUG=wayland.
|
|
|
180070 |
Instead report what display numbers were eventually found.
|
|
|
180070 |
---
|
|
|
180070 |
src/wayland/meta-xwayland.c | 123 +++++++++++++++++++++++++++---------
|
|
|
180070 |
1 file changed, 92 insertions(+), 31 deletions(-)
|
|
|
180070 |
|
|
|
180070 |
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
|
|
|
180070 |
index 15c85df69..699d5561c 100644
|
|
|
180070 |
--- a/src/wayland/meta-xwayland.c
|
|
|
180070 |
+++ b/src/wayland/meta-xwayland.c
|
|
|
180070 |
@@ -146,9 +146,10 @@ meta_xwayland_is_xwayland_surface (MetaWaylandSurface *surface)
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
static gboolean
|
|
|
180070 |
-try_display (int display,
|
|
|
180070 |
- char **filename_out,
|
|
|
180070 |
- int *fd_out)
|
|
|
180070 |
+try_display (int display,
|
|
|
180070 |
+ char **filename_out,
|
|
|
180070 |
+ int *fd_out,
|
|
|
180070 |
+ GError **error)
|
|
|
180070 |
{
|
|
|
180070 |
gboolean ret = FALSE;
|
|
|
180070 |
char *filename;
|
|
|
180070 |
@@ -164,11 +165,32 @@ try_display (int display,
|
|
|
180070 |
char pid[11];
|
|
|
180070 |
char *end;
|
|
|
180070 |
pid_t other;
|
|
|
180070 |
+ int read_bytes;
|
|
|
180070 |
|
|
|
180070 |
fd = open (filename, O_CLOEXEC, O_RDONLY);
|
|
|
180070 |
- if (fd < 0 || read (fd, pid, 11) != 11)
|
|
|
180070 |
+ if (fd < 0)
|
|
|
180070 |
{
|
|
|
180070 |
- g_warning ("can't read lock file %s: %m", filename);
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to open lock file %s: %s",
|
|
|
180070 |
+ filename, g_strerror (errno));
|
|
|
180070 |
+ goto out;
|
|
|
180070 |
+ }
|
|
|
180070 |
+
|
|
|
180070 |
+ read_bytes = read (fd, pid, 11);
|
|
|
180070 |
+ if (read_bytes != 11)
|
|
|
180070 |
+ {
|
|
|
180070 |
+ if (read_bytes < 0)
|
|
|
180070 |
+ {
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to read lock file %s: %s",
|
|
|
180070 |
+ filename, g_strerror (errno));
|
|
|
180070 |
+ }
|
|
|
180070 |
+ else
|
|
|
180070 |
+ {
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
180070 |
+ "Failed to read lock file %s",
|
|
|
180070 |
+ filename);
|
|
|
180070 |
+ }
|
|
|
180070 |
goto out;
|
|
|
180070 |
}
|
|
|
180070 |
close (fd);
|
|
|
180070 |
@@ -178,7 +200,8 @@ try_display (int display,
|
|
|
180070 |
other = strtol (pid, &end, 0);
|
|
|
180070 |
if (end != pid + 10)
|
|
|
180070 |
{
|
|
|
180070 |
- g_warning ("can't parse lock file %s", filename);
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
|
|
|
180070 |
+ "Can't parse lock file %s", filename);
|
|
|
180070 |
goto out;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
@@ -187,18 +210,23 @@ try_display (int display,
|
|
|
180070 |
/* Process is dead. Try unlinking the lock file and trying again. */
|
|
|
180070 |
if (unlink (filename) < 0)
|
|
|
180070 |
{
|
|
|
180070 |
- g_warning ("failed to unlink stale lock file %s: %m", filename);
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to unlink stale lock file %s: %m", filename);
|
|
|
180070 |
goto out;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
goto again;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
180070 |
+ "Lock file %s already occupied", filename);
|
|
|
180070 |
goto out;
|
|
|
180070 |
}
|
|
|
180070 |
else if (fd < 0)
|
|
|
180070 |
{
|
|
|
180070 |
- g_warning ("failed to create lock file %s: %m", filename);
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
180070 |
+ "Failed to create lock file %s: %s",
|
|
|
180070 |
+ filename, g_strerror (errno));
|
|
|
180070 |
goto out;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
@@ -223,24 +251,34 @@ try_display (int display,
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
static char *
|
|
|
180070 |
-create_lock_file (int display, int *display_out)
|
|
|
180070 |
+create_lock_file (int display,
|
|
|
180070 |
+ int *display_out,
|
|
|
180070 |
+ GError **error)
|
|
|
180070 |
{
|
|
|
180070 |
+ g_autoptr (GError) local_error = NULL;
|
|
|
180070 |
char *filename;
|
|
|
180070 |
int fd;
|
|
|
180070 |
-
|
|
|
180070 |
char pid[12];
|
|
|
180070 |
int size;
|
|
|
180070 |
int number_of_tries = 0;
|
|
|
180070 |
|
|
|
180070 |
- while (!try_display (display, &filename, &fd))
|
|
|
180070 |
+ while (!try_display (display, &filename, &fd, &local_error))
|
|
|
180070 |
{
|
|
|
180070 |
+ meta_verbose ("Failed to open display %d: %s\n",
|
|
|
180070 |
+ display, local_error->message);
|
|
|
180070 |
+ g_clear_error (&local_error);
|
|
|
180070 |
+
|
|
|
180070 |
display++;
|
|
|
180070 |
number_of_tries++;
|
|
|
180070 |
|
|
|
180070 |
/* If we can't get a display after 50 times, then something's wrong. Just
|
|
|
180070 |
* abort in this case. */
|
|
|
180070 |
if (number_of_tries >= 50)
|
|
|
180070 |
- return NULL;
|
|
|
180070 |
+ {
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
180070 |
+ "Tried to bind 50 display numbers, giving up");
|
|
|
180070 |
+ return NULL;
|
|
|
180070 |
+ }
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
/* Subtle detail: we use the pid of the wayland compositor, not the xserver
|
|
|
180070 |
@@ -248,11 +286,22 @@ create_lock_file (int display, int *display_out)
|
|
|
180070 |
* it _would've_ written without either the NUL or the size clamping, hence
|
|
|
180070 |
* the disparity in size. */
|
|
|
180070 |
size = snprintf (pid, 12, "%10d\n", getpid ());
|
|
|
180070 |
+ errno = 0;
|
|
|
180070 |
if (size != 11 || write (fd, pid, 11) != 11)
|
|
|
180070 |
{
|
|
|
180070 |
+ if (errno != 0)
|
|
|
180070 |
+ {
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to write pid to lock file: %s",
|
|
|
180070 |
+ g_strerror (errno));
|
|
|
180070 |
+ }
|
|
|
180070 |
+ else
|
|
|
180070 |
+ {
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
180070 |
+ "Failed to write pid to lock file");
|
|
|
180070 |
+ }
|
|
|
180070 |
unlink (filename);
|
|
|
180070 |
close (fd);
|
|
|
180070 |
- g_warning ("failed to write pid to lock file %s", filename);
|
|
|
180070 |
g_free (filename);
|
|
|
180070 |
return NULL;
|
|
|
180070 |
}
|
|
|
180070 |
@@ -264,8 +313,8 @@ create_lock_file (int display, int *display_out)
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
static int
|
|
|
180070 |
-bind_to_abstract_socket (int display,
|
|
|
180070 |
- gboolean *fatal)
|
|
|
180070 |
+bind_to_abstract_socket (int display,
|
|
|
180070 |
+ GError **error)
|
|
|
180070 |
{
|
|
|
180070 |
struct sockaddr_un addr;
|
|
|
180070 |
socklen_t size, name_size;
|
|
|
180070 |
@@ -274,8 +323,8 @@ bind_to_abstract_socket (int display,
|
|
|
180070 |
fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
|
|
180070 |
if (fd < 0)
|
|
|
180070 |
{
|
|
|
180070 |
- *fatal = TRUE;
|
|
|
180070 |
- g_warning ("Failed to create socket: %m");
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to create socket: %s", g_strerror (errno));
|
|
|
180070 |
return -1;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
@@ -285,17 +334,18 @@ bind_to_abstract_socket (int display,
|
|
|
180070 |
size = offsetof (struct sockaddr_un, sun_path) + name_size;
|
|
|
180070 |
if (bind (fd, (struct sockaddr *) &addr, size) < 0)
|
|
|
180070 |
{
|
|
|
180070 |
- *fatal = errno != EADDRINUSE;
|
|
|
180070 |
- g_warning ("failed to bind to @%s: %m", addr.sun_path + 1);
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to bind to @%s: %s",
|
|
|
180070 |
+ addr.sun_path + 1, g_strerror (errno));
|
|
|
180070 |
close (fd);
|
|
|
180070 |
return -1;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
if (listen (fd, 1) < 0)
|
|
|
180070 |
{
|
|
|
180070 |
- *fatal = errno != EADDRINUSE;
|
|
|
180070 |
- g_warning ("Failed to listen on abstract socket @%s: %m",
|
|
|
180070 |
- addr.sun_path + 1);
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to listen on abstract socket @%s: %s",
|
|
|
180070 |
+ addr.sun_path + 1, g_strerror (errno));
|
|
|
180070 |
close (fd);
|
|
|
180070 |
return -1;
|
|
|
180070 |
}
|
|
|
180070 |
@@ -304,7 +354,8 @@ bind_to_abstract_socket (int display,
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
static int
|
|
|
180070 |
-bind_to_unix_socket (int display)
|
|
|
180070 |
+bind_to_unix_socket (int display,
|
|
|
180070 |
+ GError **error)
|
|
|
180070 |
{
|
|
|
180070 |
struct sockaddr_un addr;
|
|
|
180070 |
socklen_t size, name_size;
|
|
|
180070 |
@@ -321,13 +372,18 @@ bind_to_unix_socket (int display)
|
|
|
180070 |
unlink (addr.sun_path);
|
|
|
180070 |
if (bind (fd, (struct sockaddr *) &addr, size) < 0)
|
|
|
180070 |
{
|
|
|
180070 |
- g_warning ("failed to bind to %s: %m\n", addr.sun_path);
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to bind to %s: %s",
|
|
|
180070 |
+ addr.sun_path, g_strerror (errno));
|
|
|
180070 |
close (fd);
|
|
|
180070 |
return -1;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
if (listen (fd, 1) < 0)
|
|
|
180070 |
{
|
|
|
180070 |
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
|
|
180070 |
+ "Failed to listen on %s: %s",
|
|
|
180070 |
+ addr.sun_path, g_strerror (errno));
|
|
|
180070 |
unlink (addr.sun_path);
|
|
|
180070 |
close (fd);
|
|
|
180070 |
return -1;
|
|
|
180070 |
@@ -385,7 +441,6 @@ choose_xdisplay (MetaXWaylandManager *manager)
|
|
|
180070 |
{
|
|
|
180070 |
int display = 0;
|
|
|
180070 |
char *lock_file = NULL;
|
|
|
180070 |
- gboolean fatal = FALSE;
|
|
|
180070 |
|
|
|
180070 |
if (display_number_override != -1)
|
|
|
180070 |
display = display_number_override;
|
|
|
180070 |
@@ -394,33 +449,37 @@ choose_xdisplay (MetaXWaylandManager *manager)
|
|
|
180070 |
|
|
|
180070 |
do
|
|
|
180070 |
{
|
|
|
180070 |
- lock_file = create_lock_file (display, &display);
|
|
|
180070 |
+ g_autoptr (GError) error = NULL;
|
|
|
180070 |
+
|
|
|
180070 |
+ lock_file = create_lock_file (display, &display, &error);
|
|
|
180070 |
if (!lock_file)
|
|
|
180070 |
{
|
|
|
180070 |
- g_warning ("Failed to create an X lock file");
|
|
|
180070 |
+ g_warning ("Failed to create an X lock file: %s", error->message);
|
|
|
180070 |
return FALSE;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
- manager->abstract_fd = bind_to_abstract_socket (display, &fatal);
|
|
|
180070 |
+ manager->abstract_fd = bind_to_abstract_socket (display, &error);
|
|
|
180070 |
if (manager->abstract_fd < 0)
|
|
|
180070 |
{
|
|
|
180070 |
unlink (lock_file);
|
|
|
180070 |
|
|
|
180070 |
- if (!fatal)
|
|
|
180070 |
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ADDRESS_IN_USE))
|
|
|
180070 |
{
|
|
|
180070 |
+ meta_verbose ("Failed to bind abstract socket: %s\n", error->message);
|
|
|
180070 |
display++;
|
|
|
180070 |
continue;
|
|
|
180070 |
}
|
|
|
180070 |
else
|
|
|
180070 |
{
|
|
|
180070 |
- g_warning ("Failed to bind abstract socket");
|
|
|
180070 |
+ g_warning ("Failed to bind abstract socket: %s", error->message);
|
|
|
180070 |
return FALSE;
|
|
|
180070 |
}
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
- manager->unix_fd = bind_to_unix_socket (display);
|
|
|
180070 |
+ manager->unix_fd = bind_to_unix_socket (display, &error);
|
|
|
180070 |
if (manager->unix_fd < 0)
|
|
|
180070 |
{
|
|
|
180070 |
+ meta_verbose ("Failed to bind unix socket: %s\n", error->message);
|
|
|
180070 |
unlink (lock_file);
|
|
|
180070 |
close (manager->abstract_fd);
|
|
|
180070 |
display++;
|
|
|
180070 |
@@ -435,6 +494,8 @@ choose_xdisplay (MetaXWaylandManager *manager)
|
|
|
180070 |
manager->display_name = g_strdup_printf (":%d", manager->display_index);
|
|
|
180070 |
manager->lock_file = lock_file;
|
|
|
180070 |
|
|
|
180070 |
+ g_message ("Using X11 display %s for Xwayland", manager->display_name);
|
|
|
180070 |
+
|
|
|
180070 |
return TRUE;
|
|
|
180070 |
}
|
|
|
180070 |
|
|
|
180070 |
--
|
|
|
180070 |
2.29.2
|
|
|
180070 |
|