[PATCH] Listening socket tweaks

Marty Jack martyj19 at comcast.net
Mon Feb 7 01:39:25 PST 2011


With this patch, crashed compositors won't prevent a new one from starting, and unprivileged clients can connect.

diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c
index dece0d1..6b5f503 100644
--- a/wayland/wayland-server.c
+++ b/wayland/wayland-server.c
@@ -33,6 +33,7 @@
 #include <dlfcn.h>
 #include <assert.h>
 #include <sys/time.h>
+#include <sys/stat.h>
 #include <ffi.h>
 
 #include "wayland-server.h"
@@ -675,10 +676,20 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 			     "%s/%s", runtime_dir, name) + 1;
 	fprintf(stderr, "using socket %s\n", s->addr.sun_path);
 
+	/* If the entry exists and is a socket, unlink it to prevent the bind from failing.
+	 * It is probably a socket left over from a previous compositor that crashed. */
+	struct stat stat_buf;
+	if ((stat(s->addr.sun_path, &stat_buf) == 0)
+	&& (S_ISSOCK(stat_buf.st_mode)))
+		unlink(s->addr.sun_path);
+
 	size = offsetof (struct sockaddr_un, sun_path) + name_size;
 	if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0)
 		return -1;
 
+	/* Set protections so unprivileged clients can connect. */
+	chmod(s->addr.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+
 	if (listen(s->fd, 1) < 0)
 		return -1;
 


More information about the wayland-devel mailing list