mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	server: Add a socket with an existing fd
This adds functionality to allow system-level control over handing out file descriptors for sockets, to allow tighter security when running a Wayland compositor under a Wayland session server. Allows writing socket activated Wayland servers. Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Cc: Sung-Jin Park <sj76.park@samsung.com> Cc: Sangjin Lee <lsj119@samsung.com>
This commit is contained in:
		
							parent
							
								
									87321d0f2f
								
							
						
					
					
						commit
						225830dcb8
					
				
					 2 changed files with 46 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -1198,6 +1198,49 @@ wl_display_add_socket_auto(struct wl_display *display)
 | 
			
		|||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**  Add a socket with an existing fd to Wayland display for the clients to connect.
 | 
			
		||||
 *
 | 
			
		||||
 * \param display Wayland display to which the socket should be added.
 | 
			
		||||
 * \param sock_fd The existing socket file descriptor to be used
 | 
			
		||||
 * \return 0 if success. -1 if failed.
 | 
			
		||||
 *
 | 
			
		||||
 * The existing socket fd must already be created, opened, and locked.
 | 
			
		||||
 * The fd must be properly set to CLOEXEC and bound to a socket file
 | 
			
		||||
 * with both bind() and listen() already called.
 | 
			
		||||
 *
 | 
			
		||||
 * \memberof wl_display
 | 
			
		||||
 */
 | 
			
		||||
WL_EXPORT int
 | 
			
		||||
wl_display_add_socket_fd(struct wl_display *display, 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;
 | 
			
		||||
 | 
			
		||||
	/* Reuse the existing fd */
 | 
			
		||||
	s->fd = sock_fd;
 | 
			
		||||
 | 
			
		||||
	s->source = wl_event_loop_add_fd(display->loop, s->fd,
 | 
			
		||||
					 WL_EVENT_READABLE,
 | 
			
		||||
					 socket_data, display);
 | 
			
		||||
	if (s->source == NULL) {
 | 
			
		||||
		wl_log("failed to establish event source\n");
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wl_list_insert(display->socket_list.prev, &s->link);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Add a socket to Wayland display for the clients to connect.
 | 
			
		||||
 *
 | 
			
		||||
 * \param display Wayland display to which the socket should be added.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue