[PATCH wayland v3 6/7] server: Add new API for adding a socket with an existing fd
Bryce Harrington
bryce at osg.samsung.com
Mon Dec 7 22:49:18 PST 2015
Currently the server can add a socket by name. To support an embedded
compositor in a Simplified Mandatory Access Control Kernel (Smack)
enabled environment, the embedded compositor should use the socket that
it gets from the system or session compositor.
Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
Cc: Sung-Jin Park <sj76.park at samsung.com>
Cc: Sangjin Lee <lsj119 at samsung.com>
---
src/wayland-server-core.h | 3 +++
src/wayland-server.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index 85b4b9e..530053b 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -128,6 +128,9 @@ wl_display_get_event_loop(struct wl_display *display);
int
wl_display_add_socket(struct wl_display *display, const char *name);
+int
+wl_display_add_socket_fd(struct wl_display *display, const char *name, int sock_fd);
+
const char *
wl_display_add_socket_auto(struct wl_display *display);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 7c25858..baea832 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1201,6 +1201,52 @@ wl_display_add_socket_auto(struct wl_display *display)
return NULL;
}
+WL_EXPORT int
+wl_display_add_socket_fd(struct wl_display *display, const char *name, int sock_fd)
+{
+ struct wl_socket *s;
+ struct stat buf;
+
+ /* Require a valid fd or fail */
+ if (sock_fd < 0 || fstat(sock_fd, &buf) < 0 || !S_ISSOCK(buf.st_mode)) {
+ return -1;
+ }
+
+ s = wl_socket_alloc();
+ if (s == NULL)
+ return -1;
+
+ if (name == NULL)
+ name = getenv("WAYLAND_DISPLAY");
+ if (name == NULL)
+ name = "wayland-0";
+
+ if (wl_socket_init_for_display_name(s, name) < 0) {
+ wl_socket_destroy(s);
+ return -1;
+ }
+
+ if (wl_socket_lock(s) < 0) {
+ wl_socket_destroy(s);
+ return -1;
+ }
+
+ /* Reuse the existing fd */
+ s->fd = sock_fd;
+ if (wl_os_set_cloexec_or_close(s->fd) < 0) {
+ wl_log("could not set cloexec on provided fd\n");
+ wl_socket_destroy(s);
+ return -1;
+ }
+
+ if (_wl_display_bind_socket_source(display, s) < 0) {
+ wl_socket_destroy(s);
+ return -1;
+ }
+
+ return 0;
+}
+
/** Add a socket to Wayland display for the clients to connect.
*
* \param display Wayland display to which the socket should be added.
--
1.9.1
More information about the wayland-devel
mailing list