[PATCH] server: add wl_display_destroy_clients

emersion contact at emersion.fr
Mon Dec 11 21:56:32 UTC 2017


wl_display_destroy doesn't destroy clients, so client socket file descriptors are being kept open until the compositor process exits.

To maintain ABI compatibility, we cannot destroy clients in wl_display_destroy. Thus, a new wl_display_destroy_clients functions is added and should be called by compositors right before wl_display_destroy.

See https://patchwork.freedesktop.org/patch/128832/

Signed-off-by: emersion <contact at emersion.fr>
---
 src/wayland-server-core.h |  3 +++
 src/wayland-server.c      | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index fd458c5..2e725d9 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -214,6 +214,9 @@ wl_display_run(struct wl_display *display);
 void
 wl_display_flush_clients(struct wl_display *display);
 
+void
+wl_display_destroy_clients(struct wl_display *display);
+
 struct wl_client;
 
 typedef void (*wl_global_bind_func_t)(struct wl_client *client, void *data,
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 82a3b01..7f24ef1 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1264,6 +1264,28 @@ wl_display_flush_clients(struct wl_display *display)
 	}
 }
 
+WL_EXPORT void
+wl_display_destroy_clients(struct wl_display *display)
+{
+	struct wl_list tmp_client_list;
+	struct wl_client *client, *next;
+
+	// Move the whole client list to a temporary head because some new clients
+	// might be added to the original head
+	wl_list_init(&tmp_client_list);
+	wl_list_insert_list(&tmp_client_list, &display->client_list);
+	wl_list_init(&display->client_list);
+
+	wl_list_for_each_safe(client, next, &tmp_client_list, link) {
+		wl_client_destroy(client);
+	}
+
+	if (!wl_list_empty(&display->client_list)) {
+		wl_log("wl_display_destroy_clients: cannot destroy all clients because "
+			   "new ones were created by destroy callbacks\n");
+	}
+}
+
 static int
 socket_data(int fd, uint32_t mask, void *data)
 {
-- 
2.15.1



More information about the wayland-devel mailing list