init xwm only once Xwayland server is ready

This commit is contained in:
Dominique Martinet 2017-08-19 23:09:59 +02:00
parent 3cc5b1acc6
commit 6eb20fb8d2
3 changed files with 32 additions and 9 deletions

View file

@ -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;
};

View file

@ -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;

View file

@ -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;
}