[neon/backports-noble/wayland-noble/Neon/release] src: server: add wl_display_remove_socket_fd()
Jonas Ådahl
null at kde.org
Sat Aug 22 05:55:34 BST 2026
Git commit 67af3659fac3050b422198700643f5ee13932ebd by Jonas Ådahl, on behalf of Simon Ser.
Committed on 03/07/2026 at 10:57.
Pushed by carlosdem into branch 'Neon/release'.
server: add wl_display_remove_socket_fd()
Undoes wl_display_add_socket_fd(). Useful for protocols such as:
https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/68
Signed-off-by: Simon Ser <contact at emersion.fr>
M +3 -0 src/wayland-server-core.h
M +35 -1 src/wayland-server.c
https://invent.kde.org/neon/backports-noble/wayland-noble/-/commit/67af3659fac3050b422198700643f5ee13932ebd
diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index cc08de5..757f6a1 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -205,6 +205,9 @@ wl_display_add_socket_auto(struct wl_display *display);
int
wl_display_add_socket_fd(struct wl_display *display, int sock_fd);
+int
+wl_display_remove_socket_fd(struct wl_display *display, int sock_fd);
+
void
wl_display_terminate(struct wl_display *display);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 31b597e..a0e118e 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1358,6 +1358,7 @@ wl_socket_destroy(struct wl_socket *s)
if (s->fd_lock >= 0)
close(s->fd_lock);
+ wl_list_remove(&s->link);
free(s);
}
@@ -1372,6 +1373,7 @@ wl_socket_alloc(void)
s->fd = -1;
s->fd_lock = -1;
+ wl_list_init(&s->link);
return s;
}
@@ -2040,7 +2042,8 @@ wl_display_add_socket_auto(struct wl_display *display)
* with both bind() and listen() already called.
*
* On success, the socket fd ownership is transferred to libwayland:
- * libwayland will close the socket when the display is destroyed.
+ * libwayland will close the socket when the display is destroyed or when
+ * wl_display_remove_socket_fd() is called.
*
* \memberof wl_display
*/
@@ -2076,6 +2079,37 @@ wl_display_add_socket_fd(struct wl_display *display, int sock_fd)
return 0;
}
+/** Remove a socket fd from the Wayland display.
+ *
+ * \param display Wayland display from which the socket should be removed.
+ * \param sock_fd The socket file descriptor to be removed.
+ * \return 0 if success. -1 if failed.
+ *
+ * Remove a socket fd previously added via wl_display_add_socket_fd().
+ *
+ * \memberof wl_display
+ * \since 1.25.90
+ */
+WL_EXPORT int
+wl_display_remove_socket_fd(struct wl_display *display, int sock_fd)
+{
+ struct wl_socket *s;
+ bool found;
+
+ found = false;
+ wl_list_for_each(s, &display->socket_list, link) {
+ if (s->fd == sock_fd) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ return -1;
+
+ wl_socket_destroy(s);
+ return 0;
+}
+
/** Add a socket to Wayland display for the clients to connect.
*
* \param display Wayland display to which the socket should be added.
More information about the Neon-commits
mailing list