From 3651bd54e17422d08d725f61942ee16514d3476c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Thu, 11 Aug 2011 18:59:35 -0400 Subject: [PATCH] xserver: Shut down if X server is crashing too fast --- compositor/xserver-launcher.c | 42 +++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/compositor/xserver-launcher.c b/compositor/xserver-launcher.c index a5203b76..254f7c51 100644 --- a/compositor/xserver-launcher.c +++ b/compositor/xserver-launcher.c @@ -549,13 +549,28 @@ wlsc_xserver_handle_event(int listen_fd, uint32_t mask, void *data) return 1; } +static void +wlsc_xserver_shutdown(struct wlsc_xserver *wxs) +{ + char path[256]; + + snprintf(path, sizeof path, "/tmp/.X%d-lock", wxs->display); + unlink(path); + snprintf(path, sizeof path, "/tmp/.X11-unix/X%d", wxs->display); + unlink(path); + close(wxs->abstract_fd); + wl_event_source_remove(wxs->abstract_source); + close(wxs->unix_fd); + wl_event_source_remove(wxs->unix_source); + wxs->loop = NULL; +} + static void wlsc_xserver_cleanup(struct wlsc_process *process, int status) { struct wlsc_xserver *mxs = container_of(process, struct wlsc_xserver, process); - fprintf(stderr, "xserver exited, code %d\n", status); mxs->process.pid = 0; mxs->abstract_source = @@ -568,8 +583,17 @@ wlsc_xserver_cleanup(struct wlsc_process *process, int status) WL_EVENT_READABLE, wlsc_xserver_handle_event, mxs); - wlsc_wm_destroy(mxs->wm); - mxs->wm = NULL; + if (mxs->wm) { + fprintf(stderr, "xserver exited, code %d\n", status); + wlsc_wm_destroy(mxs->wm); + mxs->wm = NULL; + } else { + /* If the X server crashes before it binds to the + * xserver interface, shut down and don't try + * again. */ + fprintf(stderr, "xserver crashing too fast: %d\n", status); + wlsc_xserver_shutdown(mxs); + } } static void @@ -790,15 +814,9 @@ void wlsc_xserver_destroy(struct wlsc_compositor *compositor) { struct wlsc_xserver *wxs = compositor->wxs; - char path[256]; - snprintf(path, sizeof path, "/tmp/.X%d-lock", wxs->display); - unlink(path); - snprintf(path, sizeof path, "/tmp/.X11-unix/X%d", wxs->display); - unlink(path); - close(wxs->abstract_fd); - wl_event_source_remove(wxs->abstract_source); - close(wxs->unix_fd); - wl_event_source_remove(wxs->unix_source); + if (wxs->loop) + wlsc_xserver_shutdown(wxs); + free(wxs); }