diff --git a/xwayland/sockets.c b/xwayland/sockets.c index a91e049e0..f1ab752fa 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -63,18 +63,35 @@ static bool check_socket_dir(void) { return true; } -static int open_socket(int display) { - if (mkdir(socket_dir, 0755) == 0) { - wlr_log(WLR_INFO, "Created %s ourselves -- other users will " - "be unable to create X11 UNIX sockets of their own", - socket_dir); - } else if (errno != EEXIST) { +static bool setup_socket_dir(void) { + mode_t dir_mode = 01777; + + 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; - } else if (!check_socket_dir()) { + } + + wlr_log(WLR_INFO, "Created %s ourselves -- other users will " + "be unable to create X11 UNIX sockets of their own", + socket_dir); + + // The mode passed to mkdir() is affected by umask, so set it again + if (chmod(socket_dir, dir_mode) != 0) { + wlr_log_errno(WLR_ERROR, "Failed to chmod %s", socket_dir); return false; } + return true; +} + +static int open_socket(int display) { + if (!setup_socket_dir()) { + return -1; + } + struct sockaddr_un addr = { .sun_family = AF_UNIX }; size_t path_size = snprintf(addr.sun_path, sizeof(addr.sun_path), socket_fmt, display);