mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-14 08:22:25 -04:00
Merge branch 'xwl-drop-abstract-socket' into 'master'
Draft: xwayland: drop support for abstract sockets See merge request wlroots/wlroots!4656
This commit is contained in:
commit
d3599f8dce
4 changed files with 80 additions and 120 deletions
|
|
@ -35,8 +35,8 @@ struct wlr_xwayland_server {
|
||||||
|
|
||||||
int display;
|
int display;
|
||||||
char display_name[16];
|
char display_name[16];
|
||||||
int x_fd[2];
|
int x_fd;
|
||||||
struct wl_event_source *x_fd_read_event[2];
|
struct wl_event_source *x_fd_read_event;
|
||||||
struct wlr_xwayland_server_options options;
|
struct wlr_xwayland_server_options options;
|
||||||
|
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ static void safe_close(int fd) {
|
||||||
|
|
||||||
noreturn static void exec_xwayland(struct wlr_xwayland_server *server,
|
noreturn static void exec_xwayland(struct wlr_xwayland_server *server,
|
||||||
int notify_fd) {
|
int notify_fd) {
|
||||||
if (!set_cloexec(server->x_fd[0], false) ||
|
if (!set_cloexec(server->x_fd, false) ||
|
||||||
!set_cloexec(server->x_fd[1], false) ||
|
|
||||||
!set_cloexec(server->wl_fd[1], false)) {
|
!set_cloexec(server->wl_fd[1], false)) {
|
||||||
wlr_log(WLR_ERROR, "Failed to unset CLOEXEC on FD");
|
wlr_log(WLR_ERROR, "Failed to unset CLOEXEC on FD");
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
|
|
@ -39,9 +38,8 @@ noreturn static void exec_xwayland(struct wlr_xwayland_server *server,
|
||||||
char *argv[64] = {0};
|
char *argv[64] = {0};
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
char listenfd0[16], listenfd1[16], displayfd[16];
|
char listenfd[16], displayfd[16];
|
||||||
snprintf(listenfd0, sizeof(listenfd0), "%d", server->x_fd[0]);
|
snprintf(listenfd, sizeof(listenfd), "%d", server->x_fd);
|
||||||
snprintf(listenfd1, sizeof(listenfd1), "%d", server->x_fd[1]);
|
|
||||||
snprintf(displayfd, sizeof(displayfd), "%d", notify_fd);
|
snprintf(displayfd, sizeof(displayfd), "%d", notify_fd);
|
||||||
|
|
||||||
argv[i++] = "Xwayland";
|
argv[i++] = "Xwayland";
|
||||||
|
|
@ -61,14 +59,10 @@ noreturn static void exec_xwayland(struct wlr_xwayland_server *server,
|
||||||
|
|
||||||
#if HAVE_XWAYLAND_LISTENFD
|
#if HAVE_XWAYLAND_LISTENFD
|
||||||
argv[i++] = "-listenfd";
|
argv[i++] = "-listenfd";
|
||||||
argv[i++] = listenfd0;
|
argv[i++] = listenfd;
|
||||||
argv[i++] = "-listenfd";
|
|
||||||
argv[i++] = listenfd1;
|
|
||||||
#else
|
#else
|
||||||
argv[i++] = "-listen";
|
argv[i++] = "-listen";
|
||||||
argv[i++] = listenfd0;
|
argv[i++] = listenfd;
|
||||||
argv[i++] = "-listen";
|
|
||||||
argv[i++] = listenfd1;
|
|
||||||
#endif
|
#endif
|
||||||
argv[i++] = "-displayfd";
|
argv[i++] = "-displayfd";
|
||||||
argv[i++] = displayfd;
|
argv[i++] = displayfd;
|
||||||
|
|
@ -141,11 +135,9 @@ static void server_finish_process(struct wlr_xwayland_server *server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server->x_fd_read_event[0]) {
|
if (server->x_fd_read_event) {
|
||||||
wl_event_source_remove(server->x_fd_read_event[0]);
|
wl_event_source_remove(server->x_fd_read_event);
|
||||||
wl_event_source_remove(server->x_fd_read_event[1]);
|
server->x_fd_read_event = NULL;
|
||||||
|
|
||||||
server->x_fd_read_event[0] = server->x_fd_read_event[1] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server->client) {
|
if (server->client) {
|
||||||
|
|
@ -182,9 +174,8 @@ static void server_finish_display(struct wlr_xwayland_server *server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_close(server->x_fd[0]);
|
safe_close(server->x_fd);
|
||||||
safe_close(server->x_fd[1]);
|
server->x_fd = -1;
|
||||||
server->x_fd[0] = server->x_fd[1] = -1;
|
|
||||||
|
|
||||||
unlink_display_sockets(server->display);
|
unlink_display_sockets(server->display);
|
||||||
server->display = -1;
|
server->display = -1;
|
||||||
|
|
@ -309,7 +300,7 @@ static bool server_start_display(struct wlr_xwayland_server *server,
|
||||||
server->display_destroy.notify = handle_display_destroy;
|
server->display_destroy.notify = handle_display_destroy;
|
||||||
wl_display_add_destroy_listener(wl_display, &server->display_destroy);
|
wl_display_add_destroy_listener(wl_display, &server->display_destroy);
|
||||||
|
|
||||||
server->display = open_display_sockets(server->x_fd);
|
server->display = open_display_sockets(&server->x_fd);
|
||||||
if (server->display < 0) {
|
if (server->display < 0) {
|
||||||
server_finish_display(server);
|
server_finish_display(server);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -412,9 +403,8 @@ static bool server_start(struct wlr_xwayland_server *server) {
|
||||||
static int xwayland_socket_connected(int fd, uint32_t mask, void *data) {
|
static int xwayland_socket_connected(int fd, uint32_t mask, void *data) {
|
||||||
struct wlr_xwayland_server *server = data;
|
struct wlr_xwayland_server *server = data;
|
||||||
|
|
||||||
wl_event_source_remove(server->x_fd_read_event[0]);
|
wl_event_source_remove(server->x_fd_read_event);
|
||||||
wl_event_source_remove(server->x_fd_read_event[1]);
|
server->x_fd_read_event = NULL;
|
||||||
server->x_fd_read_event[0] = server->x_fd_read_event[1] = NULL;
|
|
||||||
|
|
||||||
server_start(server);
|
server_start(server);
|
||||||
|
|
||||||
|
|
@ -424,18 +414,11 @@ static int xwayland_socket_connected(int fd, uint32_t mask, void *data) {
|
||||||
static bool server_start_lazy(struct wlr_xwayland_server *server) {
|
static bool server_start_lazy(struct wlr_xwayland_server *server) {
|
||||||
struct wl_event_loop *loop = wl_display_get_event_loop(server->wl_display);
|
struct wl_event_loop *loop = wl_display_get_event_loop(server->wl_display);
|
||||||
|
|
||||||
if (!(server->x_fd_read_event[0] = wl_event_loop_add_fd(loop, server->x_fd[0],
|
if (!(server->x_fd_read_event = wl_event_loop_add_fd(loop, server->x_fd,
|
||||||
WL_EVENT_READABLE, xwayland_socket_connected, server))) {
|
WL_EVENT_READABLE, xwayland_socket_connected, server))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(server->x_fd_read_event[1] = wl_event_loop_add_fd(loop, server->x_fd[1],
|
|
||||||
WL_EVENT_READABLE, xwayland_socket_connected, server))) {
|
|
||||||
wl_event_source_remove(server->x_fd_read_event[0]);
|
|
||||||
server->x_fd_read_event[0] = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -485,7 +468,7 @@ struct wlr_xwayland_server *wlr_xwayland_server_create(
|
||||||
server->options.terminate_delay = 0;
|
server->options.terminate_delay = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server->x_fd[0] = server->x_fd[1] = -1;
|
server->x_fd = -1;
|
||||||
server->wl_fd[0] = server->wl_fd[1] = -1;
|
server->wl_fd[0] = server->wl_fd[1] = -1;
|
||||||
server->wm_fd[0] = server->wm_fd[1] = -1;
|
server->wm_fd[0] = server->wm_fd[1] = -1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,6 @@
|
||||||
static const char lock_fmt[] = "/tmp/.X%d-lock";
|
static const char lock_fmt[] = "/tmp/.X%d-lock";
|
||||||
static const char socket_dir[] = "/tmp/.X11-unix";
|
static const char socket_dir[] = "/tmp/.X11-unix";
|
||||||
static const char socket_fmt[] = "/tmp/.X11-unix/X%d";
|
static const char socket_fmt[] = "/tmp/.X11-unix/X%d";
|
||||||
#ifndef __linux__
|
|
||||||
static const char socket_fmt2[] = "/tmp/.X11-unix/X%d_";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool set_cloexec(int fd, bool cloexec) {
|
bool set_cloexec(int fd, bool cloexec) {
|
||||||
int flags = fcntl(fd, F_GETFD);
|
int flags = fcntl(fd, F_GETFD);
|
||||||
|
|
@ -40,51 +37,6 @@ bool set_cloexec(int fd, bool cloexec) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_socket(struct sockaddr_un *addr, size_t path_size) {
|
|
||||||
int fd, rc;
|
|
||||||
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
|
|
||||||
|
|
||||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (fd < 0) {
|
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to create socket %c%s",
|
|
||||||
addr->sun_path[0] ? addr->sun_path[0] : '@',
|
|
||||||
addr->sun_path + 1);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!set_cloexec(fd, true)) {
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addr->sun_path[0]) {
|
|
||||||
unlink(addr->sun_path);
|
|
||||||
}
|
|
||||||
if (bind(fd, (struct sockaddr*)addr, size) < 0) {
|
|
||||||
rc = errno;
|
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to bind socket %c%s",
|
|
||||||
addr->sun_path[0] ? addr->sun_path[0] : '@',
|
|
||||||
addr->sun_path + 1);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (listen(fd, 1) < 0) {
|
|
||||||
rc = errno;
|
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to listen to socket %c%s",
|
|
||||||
addr->sun_path[0] ? addr->sun_path[0] : '@',
|
|
||||||
addr->sun_path + 1);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
close(fd);
|
|
||||||
if (addr->sun_path[0]) {
|
|
||||||
unlink(addr->sun_path);
|
|
||||||
}
|
|
||||||
errno = rc;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool check_socket_dir(void) {
|
static bool check_socket_dir(void) {
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
|
|
@ -111,66 +63,91 @@ static bool check_socket_dir(void) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool open_sockets(int socks[2], int display) {
|
static bool setup_socket_dir(void) {
|
||||||
struct sockaddr_un addr = { .sun_family = AF_UNIX };
|
mode_t dir_mode = 01777;
|
||||||
size_t path_size;
|
|
||||||
|
if (mkdir(socket_dir, dir_mode) != 0) {
|
||||||
|
if (errno == EEXIST) {
|
||||||
|
return check_socket_dir();
|
||||||
|
}
|
||||||
|
wlr_log_errno(WLR_ERROR, "Unable to mkdir %s", socket_dir);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (mkdir(socket_dir, 0755) == 0) {
|
|
||||||
wlr_log(WLR_INFO, "Created %s ourselves -- other users will "
|
wlr_log(WLR_INFO, "Created %s ourselves -- other users will "
|
||||||
"be unable to create X11 UNIX sockets of their own",
|
"be unable to create X11 UNIX sockets of their own",
|
||||||
socket_dir);
|
socket_dir);
|
||||||
} else if (errno != EEXIST) {
|
|
||||||
wlr_log_errno(WLR_ERROR, "Unable to mkdir %s", socket_dir);
|
|
||||||
return false;
|
|
||||||
} else if (!check_socket_dir()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __linux__
|
// The mode passed to mkdir() is affected by umask, so set it again
|
||||||
addr.sun_path[0] = 0;
|
if (chmod(socket_dir, dir_mode) != 0) {
|
||||||
path_size = snprintf(addr.sun_path + 1, sizeof(addr.sun_path) - 1, socket_fmt, display);
|
wlr_log_errno(WLR_ERROR, "Failed to chmod %s", socket_dir);
|
||||||
#else
|
|
||||||
path_size = snprintf(addr.sun_path, sizeof(addr.sun_path), socket_fmt2, display);
|
|
||||||
#endif
|
|
||||||
socks[0] = open_socket(&addr, path_size);
|
|
||||||
if (socks[0] < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
path_size = snprintf(addr.sun_path, sizeof(addr.sun_path), socket_fmt, display);
|
|
||||||
socks[1] = open_socket(&addr, path_size);
|
|
||||||
if (socks[1] < 0) {
|
|
||||||
close(socks[0]);
|
|
||||||
socks[0] = -1;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unlink_display_sockets(int display) {
|
static int open_socket(int display) {
|
||||||
char sun_path[64];
|
if (!setup_socket_dir()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(sun_path, sizeof(sun_path), socket_fmt, display);
|
struct sockaddr_un addr = { .sun_family = AF_UNIX };
|
||||||
unlink(sun_path);
|
size_t path_size = snprintf(addr.sun_path, sizeof(addr.sun_path), socket_fmt, display);
|
||||||
|
|
||||||
#ifndef __linux__
|
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
|
||||||
snprintf(sun_path, sizeof(sun_path), socket_fmt2, display);
|
|
||||||
unlink(sun_path);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
snprintf(sun_path, sizeof(sun_path), lock_fmt, display);
|
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
unlink(sun_path);
|
if (fd < 0) {
|
||||||
|
wlr_log_errno(WLR_ERROR, "Failed to create socket %s", addr.sun_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!set_cloexec(fd, true)) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc;
|
||||||
|
unlink(addr.sun_path);
|
||||||
|
if (bind(fd, (struct sockaddr *)&addr, size) < 0) {
|
||||||
|
rc = errno;
|
||||||
|
wlr_log_errno(WLR_ERROR, "Failed to bind socket %s", addr.sun_path);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (listen(fd, 1) < 0) {
|
||||||
|
rc = errno;
|
||||||
|
wlr_log_errno(WLR_ERROR, "Failed to listen to socket %s", addr.sun_path);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
close(fd);
|
||||||
|
unlink(addr.sun_path);
|
||||||
|
errno = rc;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int open_display_sockets(int socks[2]) {
|
void unlink_display_sockets(int display) {
|
||||||
|
char path[64];
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path), socket_fmt, display);
|
||||||
|
unlink(path);
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path), lock_fmt, display);
|
||||||
|
unlink(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
int open_display_sockets(int *sock) {
|
||||||
int lock_fd, display;
|
int lock_fd, display;
|
||||||
char lock_name[64];
|
char lock_name[64];
|
||||||
|
|
||||||
for (display = 0; display <= 32; display++) {
|
for (display = 0; display <= 32; display++) {
|
||||||
snprintf(lock_name, sizeof(lock_name), lock_fmt, display);
|
snprintf(lock_name, sizeof(lock_name), lock_fmt, display);
|
||||||
if ((lock_fd = open(lock_name, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0444)) >= 0) {
|
if ((lock_fd = open(lock_name, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0444)) >= 0) {
|
||||||
if (!open_sockets(socks, display)) {
|
*sock = open_socket(display);
|
||||||
|
if (*sock < 0) {
|
||||||
unlink(lock_name);
|
unlink(lock_name);
|
||||||
close(lock_fd);
|
close(lock_fd);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@
|
||||||
|
|
||||||
bool set_cloexec(int fd, bool cloexec);
|
bool set_cloexec(int fd, bool cloexec);
|
||||||
void unlink_display_sockets(int display);
|
void unlink_display_sockets(int display);
|
||||||
int open_display_sockets(int socks[2]);
|
int open_display_sockets(int *sock);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue