[mutter] xwayland: Avoid late errno checks
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] xwayland: Avoid late errno checks
- Date: Sat, 6 Aug 2016 15:17:09 +0000 (UTC)
commit 5c9a2c54c4ee9f76a6b3af71335a9b4caa1cc7d1
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Aug 6 16:17:33 2016 +0200
xwayland: Avoid late errno checks
We do some things when binding to a socket fails (closing the fd,
logging, unlinking files, ...) those might affect errno in some
or other way, so it might no longer be EADDRINUSE even if we later
try to make those non fatal.
It seems better to check errno soon after the failure, and don't
rely on it in any way at a later point. All error paths in
bind_to_abstract_socket() also have early logging, which also might
help figure out better the point of failure when the socket fails
to be created.
https://bugzilla.gnome.org/show_bug.cgi?id=769578
src/wayland/meta-xwayland.c | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index 1b96ce5..0cf966e 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -299,7 +299,8 @@ create_lock_file (int display, int *display_out)
}
static int
-bind_to_abstract_socket (int display)
+bind_to_abstract_socket (int display,
+ gboolean *fatal)
{
struct sockaddr_un addr;
socklen_t size, name_size;
@@ -307,7 +308,11 @@ bind_to_abstract_socket (int display)
fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd < 0)
- return -1;
+ {
+ *fatal = TRUE;
+ g_warning ("Failed to create socket: %m");
+ return -1;
+ }
addr.sun_family = AF_LOCAL;
name_size = snprintf (addr.sun_path, sizeof addr.sun_path,
@@ -315,6 +320,7 @@ bind_to_abstract_socket (int display)
size = offsetof (struct sockaddr_un, sun_path) + name_size;
if (bind (fd, (struct sockaddr *) &addr, size) < 0)
{
+ *fatal = errno != EADDRINUSE;
g_warning ("failed to bind to @%s: %m", addr.sun_path + 1);
close (fd);
return -1;
@@ -322,6 +328,9 @@ bind_to_abstract_socket (int display)
if (listen (fd, 1) < 0)
{
+ *fatal = errno != EADDRINUSE;
+ g_warning ("Failed to listen on abstract socket @%s: %m",
+ addr.sun_path + 1);
close (fd);
return -1;
}
@@ -394,6 +403,7 @@ choose_xdisplay (MetaXWaylandManager *manager)
{
int display = 0;
char *lock_file = NULL;
+ gboolean fatal = FALSE;
/* Hack to keep the unused Xwayland instance on
* the login screen from taking the prime :0 display
@@ -411,18 +421,21 @@ choose_xdisplay (MetaXWaylandManager *manager)
return FALSE;
}
- manager->abstract_fd = bind_to_abstract_socket (display);
+ manager->abstract_fd = bind_to_abstract_socket (display, &fatal);
if (manager->abstract_fd < 0)
{
unlink (lock_file);
- if (errno == EADDRINUSE)
+ if (!fatal)
{
display++;
continue;
}
else
- return FALSE;
+ {
+ g_warning ("Failed to bind abstract socket");
+ return FALSE;
+ }
}
manager->unix_fd = bind_to_unix_socket (display);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]