kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

Blame SOURCES/0001-xwayland-Don-t-spew-warnings-when-looking-for-X11-di.patch

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