[PATCH wayland v3 5/7] server: Restructure _wl_display_add_socket() to take an explicit fd argument

Bryce Harrington bryce at osg.samsung.com
Mon Dec 7 22:49:17 PST 2015


Move the the wl_os_socket_cloexec() to the callers.

Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 src/wayland-server.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 0f04f66..7c25858 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1129,15 +1129,10 @@ wl_socket_init_for_display_name(struct wl_socket *s, const char *name)
 }
 
 static int
-_wl_display_add_socket(struct wl_display *display, struct wl_socket *s)
+_wl_display_bind_socket_source(struct wl_display *display, struct wl_socket *s)
 {
 	socklen_t size;
 
-	s->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
-	if (s->fd < 0) {
-		return -1;
-	}
-
 	size = offsetof (struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
 	if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
 		wl_log("bind() failed with error: %m\n");
@@ -1153,6 +1148,7 @@ _wl_display_add_socket(struct wl_display *display, struct wl_socket *s)
 					 WL_EVENT_READABLE,
 					 socket_data, display);
 	if (s->source == NULL) {
+		wl_log("failed to establish event source\n");
 		return -1;
 	}
 
@@ -1185,7 +1181,13 @@ wl_display_add_socket_auto(struct wl_display *display)
 		if (wl_socket_lock(s) < 0)
 			continue;
 
-		if (_wl_display_add_socket(display, s) < 0) {
+		s->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
+		if (s->fd < 0) {
+			wl_socket_destroy(s);
+			return NULL;
+		}
+
+		if (_wl_display_bind_socket_source(display, s) < 0) {
 			wl_socket_destroy(s);
 			return NULL;
 		}
@@ -1247,7 +1249,13 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 		return -1;
 	}
 
-	if (_wl_display_add_socket(display, s) < 0) {
+	s->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
+	if (s->fd <0) {
+		wl_socket_destroy(s);
+		return -1;
+	}
+
+	if (_wl_display_bind_socket_source(display, s) < 0) {
 		wl_socket_destroy(s);
 		return -1;
 	}
-- 
1.9.1



More information about the wayland-devel mailing list