xwayland: fix some shutdown cases

This commit is contained in:
Dominique Martinet 2017-08-23 23:19:15 +02:00
parent fd3ad3b9e4
commit e3143b50b6
3 changed files with 35 additions and 18 deletions

View File

@ -24,7 +24,9 @@ static int open_socket(struct sockaddr_un *addr, size_t path_size) {
fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd < 0) {
wlr_log_errno(L_ERROR, "Failed to create socket %s", addr->sun_path);
wlr_log_errno(L_DEBUG, "Failed to create socket %c%s",
addr->sun_path[0] ? addr->sun_path[0] : '@',
addr->sun_path + 1);
return -1;
}
@ -33,12 +35,16 @@ static int open_socket(struct sockaddr_un *addr, size_t path_size) {
}
if (bind(fd, (struct sockaddr*)addr, size) < 0) {
rc = errno;
wlr_log_errno(L_ERROR, "Failed to bind socket %s", addr->sun_path);
wlr_log_errno(L_DEBUG, "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(L_ERROR, "Failed to listen to socket %s", addr->sun_path);
wlr_log_errno(L_DEBUG, "Failed to listen to socket %c%s",
addr->sun_path[0] ? addr->sun_path[0] : '@',
addr->sun_path + 1);
goto cleanup;
}

View File

@ -6,6 +6,8 @@
#include <fcntl.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <stdlib.h>
#include <errno.h>
@ -93,9 +95,9 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
snprintf(wayland_socket_str, sizeof(wayland_socket_str), "%d", wlr_xwayland->wl_fd[1]);
setenv("WAYLAND_SOCKET", wayland_socket_str, true);
wlr_log(L_INFO, "Xwayland :%d -rootless -terminate -listen %d -listen %d -wm %d",
wlr_xwayland->display, wlr_xwayland->x_fd[0], wlr_xwayland->x_fd[1],
wlr_xwayland->wm_fd[1]);
wlr_log(L_INFO, "WAYLAND_SOCKET=%d Xwayland :%d -rootless -terminate -listen %d -listen %d -wm %d",
wlr_xwayland->wl_fd[1], wlr_xwayland->display, wlr_xwayland->x_fd[0],
wlr_xwayland->x_fd[1], wlr_xwayland->wm_fd[1]);
// TODO: close stdout/err depending on log level
@ -111,20 +113,23 @@ static void xwayland_destroy_event(struct wl_listener *listener, void *data) {
/* don't call client destroy */
wlr_xwayland->client = NULL;
wl_list_remove(&wlr_xwayland->destroy_listener.link);
wlr_xwayland_finish(wlr_xwayland);
if (wlr_xwayland->server_start - time(NULL) > 5) {
if (time(NULL) - wlr_xwayland->server_start > 5) {
wlr_xwayland_init(wlr_xwayland, wlr_xwayland->wl_display,
wlr_xwayland->compositor);
wlr_xwayland->compositor);
}
}
static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) {
if (!wlr_xwayland || wlr_xwayland->display == -1) {
return;
}
if (wlr_xwayland->client) {
wl_list_remove(&wlr_xwayland->destroy_listener.link);
wl_client_destroy(wlr_xwayland->client);
}
if (wlr_xwayland->sigusr1_source) {
wl_event_source_remove(wlr_xwayland->sigusr1_source);
}
@ -142,10 +147,13 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) {
safe_close(wlr_xwayland->wm_fd[1]);
unlink_display_sockets(wlr_xwayland->display);
wlr_xwayland->display = -1;
unsetenv("DISPLAY");
/* We do not kill the Xwayland process, it dies because of broken pipe
* after we close our side of the wm/wl fds. This is more reliable than
* trying to kill something that might no longer be Xwayland */
/* We do not kill the Xwayland process, it dies to broken pipe
* after we close our side of the wm/wl fds. This is more reliable
* than trying to kill something that might no longer be Xwayland.
*/
// TODO: figure how to wait for dying process though. Probably handle SIGCHILD
}
static int xserver_handle_ready(int signal_number, void *data) {

View File

@ -61,7 +61,7 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line,
}
wlr_log(L_ERROR, "xcb call failed in %s:%u, x11 error code %d",
func, line, error->error_code);
func, line, error->error_code);
free(error);
return false;
}
@ -79,7 +79,7 @@ static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window
static void handle_create_notify(struct wlr_xwm *xwm, xcb_create_notify_event_t *ev) {
wlr_log(L_DEBUG, "XCB_CREATE_NOTIFY (%u)", ev->window);
wlr_x11_window_create(xwm, ev->window, ev->x, ev->y,
ev->width, ev->height, ev->override_redirect);
ev->width, ev->height, ev->override_redirect);
}
static void handle_destroy_notify(struct wlr_xwm *xwm, xcb_destroy_notify_event_t *ev) {
@ -94,7 +94,7 @@ static void handle_destroy_notify(struct wlr_xwm *xwm, xcb_destroy_notify_event_
static void handle_configure_request(struct wlr_xwm *xwm, xcb_configure_request_event_t *ev) {
struct wlr_x11_window *window;
wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window,
ev->width, ev->height, ev->x, ev->y);
ev->width, ev->height, ev->x, ev->y);
if (!(window = lookup_window_any(xwm, ev->window))) {
return;
}
@ -154,7 +154,7 @@ static void handle_client_message(struct wlr_xwm *xwm, xcb_client_message_event_
window = lookup_window(&xwm->new_windows, ev->window);
if (!window) {
wlr_log(L_DEBUG, "client message WL_SURFACE_ID but no new window %u ?",
ev->window);
ev->window);
return;
}
window->surface_id = ev->data.data32[0];
@ -260,7 +260,7 @@ static void xcb_get_resources(struct wlr_xwm *xwm) {
}
if (error) {
wlr_log(L_ERROR, "could not resolve atom %s, x11 error code %d",
atom_map[i], error->error_code);
atom_map[i], error->error_code);
free(error);
return;
}
@ -304,10 +304,13 @@ static void xcb_init_wm(struct wlr_xwm *xwm) {
}
void xwm_destroy(struct wlr_xwm *xwm) {
if (!xwm) {
return;
}
if (xwm->event_source) {
wl_event_source_remove(xwm->event_source);
}
wl_list_remove(&xwm->surface_create_listener.link);
xcb_disconnect(xwm->xcb_conn);
free(xwm);