From 6eb20fb8d28749e0b710a54daa1b916080cf4ea1 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 19 Aug 2017 23:09:59 +0200 Subject: init xwm only once Xwayland server is ready --- include/wlr/xwayland.h | 1 + xwayland/sockets.c | 5 ++++- xwayland/xwayland.c | 35 +++++++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index f61a90bd..bbb315e2 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -16,6 +16,7 @@ struct wlr_xwayland { struct wlr_compositor *compositor; time_t server_start; + struct wl_event_source *sigusr1_source; struct wlr_xwm *xwm; }; diff --git a/xwayland/sockets.c b/xwayland/sockets.c index 868d6ada..714969fe 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -83,6 +83,9 @@ void unlink_sockets(int display) { snprintf(sun_path, sizeof(sun_path), socket_fmt, display); unlink(sun_path); + + snprintf(sun_path, sizeof(sun_path), lock_fmt, display); + unlink(sun_path); } int open_display_sockets(int socks[2]) { @@ -121,7 +124,7 @@ int open_display_sockets(int socks[2]) { } long int read_pid; read_pid = strtol(pid, &end_pid, 10); - if (read_pid < 0 || read_pid > INT32_MAX || end_pid != pid + sizeof(pid)) { + if (read_pid < 0 || read_pid > INT32_MAX || end_pid != pid + sizeof(pid) - 2) { continue; } errno = 0; diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index e9bdfcc5..e998db28 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -35,6 +35,9 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) { exit(EXIT_FAILURE); } + /* Make Xwayland signal us when it's ready */ + signal(SIGUSR1, SIG_IGN); + char *argv[11] = { 0 }; argv[0] = "Xwayland"; if (asprintf(&argv[1], ":%d", wlr_xwayland->display) < 0) { @@ -106,6 +109,10 @@ void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { wl_client_destroy(wlr_xwayland->client); } + if (wlr_xwayland->sigusr1_source) { + wl_event_source_remove(wlr_xwayland->sigusr1_source); + } + xwm_destroy(wlr_xwayland->xwm); safe_close(wlr_xwayland->x_fd[0]); @@ -120,6 +127,24 @@ void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { /* kill Xwayland process? */ } +static int xserver_handle_ready(int signal_number, void *data) { + struct wlr_xwayland *wlr_xwayland = data; + + wlr_log(L_DEBUG, "Xserver is ready"); + + wlr_xwayland->xwm = xwm_create(wlr_xwayland); + if (!wlr_xwayland->xwm) { + wlr_xwayland_finish(wlr_xwayland); + return 1; + } + + char display_name[16]; + snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); + setenv("DISPLAY", display_name, true); + + return 1; +} + bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, struct wl_display *wl_display, struct wlr_compositor *compositor) { memset(wlr_xwayland, 0, sizeof(struct wlr_xwayland)); @@ -161,9 +186,6 @@ bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1; wlr_xwayland->wl_fd[1] = wlr_xwayland->wm_fd[1] = -1; - char display_name[16]; - snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); - setenv("DISPLAY", display_name, true); wlr_xwayland->server_start = time(NULL); if (!(wlr_xwayland->client = wl_client_create(wl_display, wlr_xwayland->wl_fd[0]))) { @@ -174,11 +196,8 @@ bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wl_client_add_destroy_listener(wlr_xwayland->client, &xwayland_destroy_listener); - wlr_xwayland->xwm = xwm_create(wlr_xwayland); - if (!wlr_xwayland->xwm) { - wlr_xwayland_finish(wlr_xwayland); - return false; - } + struct wl_event_loop *loop = wl_display_get_event_loop(wl_display); + wlr_xwayland->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1, xserver_handle_ready, wlr_xwayland); return true; } -- cgit v1.2.3