From e3143b50b6363bb7408e30aa64acdbdcd9b249d9 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 23 Aug 2017 23:19:15 +0200 Subject: [PATCH] xwayland: fix some shutdown cases --- xwayland/sockets.c | 12 +++++++++--- xwayland/xwayland.c | 26 +++++++++++++++++--------- xwayland/xwm.c | 15 +++++++++------ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/xwayland/sockets.c b/xwayland/sockets.c index ca46ec9f..48bcc822 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -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; } diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index 9c0b1839..9ac94e72 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -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) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 0e161330..3cd5b22b 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -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);