From caa64425564a54431dd8304e005430a453cc2e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 1 Dec 2010 16:52:15 -0500 Subject: [PATCH] compositor: Use a virtual destructor when shutting down Backend can now rely on their destroy function getting called on shutdown, so reset tty etc there instead of handling SIGTERM twice. --- compositor/compositor-drm.c | 30 ++++++++++++++---------------- compositor/compositor-wayland.c | 7 +++++++ compositor/compositor-x11.c | 7 +++++++ compositor/compositor.c | 2 ++ compositor/compositor.h | 1 + 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/compositor/compositor-drm.c b/compositor/compositor-drm.c index e3e9b6fb..1d04c060 100644 --- a/compositor/compositor-drm.c +++ b/compositor/compositor-drm.c @@ -42,9 +42,7 @@ struct drm_compositor { struct udev *udev; struct wl_event_source *drm_source; - struct wl_event_source *term_signal_source; - - /* tty handling state */ + /* tty handling state */ int tty_fd; uint32_t vt_active : 1; @@ -559,16 +557,6 @@ on_tty_input(int fd, uint32_t mask, void *data) tcflush(ec->tty_fd, TCIFLUSH); } -static void on_term_signal(int signal_number, void *data) -{ - struct drm_compositor *ec = data; - - if (tcsetattr(ec->tty_fd, TCSANOW, &ec->terminal_attributes) < 0) - fprintf(stderr, "could not restore terminal to canonical mode\n"); - - exit(0); -} - static int setup_tty(struct drm_compositor *ec, struct wl_event_loop *loop) { struct termios raw_attributes; @@ -596,9 +584,6 @@ static int setup_tty(struct drm_compositor *ec, struct wl_event_loop *loop) if (tcsetattr(ec->tty_fd, TCSANOW, &raw_attributes) < 0) fprintf(stderr, "could not put terminal into raw mode: %m\n"); - ec->term_signal_source = - wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, ec); - ec->tty_input_source = wl_event_loop_add_fd(loop, ec->tty_fd, WL_EVENT_READABLE, on_tty_input, ec); @@ -631,6 +616,18 @@ drm_authenticate(struct wlsc_compositor *c, uint32_t id) return drmAuthMagic(ec->base.drm.fd, id); } +static void +drm_destroy(struct wlsc_compositor *ec) +{ + struct drm_compositor *d = (struct drm_compositor *) ec; + + if (tcsetattr(d->tty_fd, TCSANOW, &d->terminal_attributes) < 0) + fprintf(stderr, + "could not restore terminal to canonical mode\n"); + + free(ec); +} + struct wlsc_compositor * drm_compositor_create(struct wl_display *display, int connector) { @@ -691,6 +688,7 @@ drm_compositor_create(struct wl_display *display, int connector) wl_event_loop_add_fd(loop, ec->base.drm.fd, WL_EVENT_READABLE, on_drm_input, ec); setup_tty(ec, loop); + ec->base.destroy = drm_destroy; ec->base.authenticate = drm_authenticate; ec->base.present = drm_compositor_present; ec->base.focus = 1; diff --git a/compositor/compositor-wayland.c b/compositor/compositor-wayland.c index e289a292..fa630bc0 100644 --- a/compositor/compositor-wayland.c +++ b/compositor/compositor-wayland.c @@ -507,6 +507,12 @@ wayland_compositor_handle_event(int fd, uint32_t mask, void *data) wl_display_iterate(c->parent.display, WL_DISPLAY_WRITABLE); } +static void +wayland_destroy(struct wlsc_compositor *ec) +{ + free(ec); +} + struct wlsc_compositor * wayland_compositor_create(struct wl_display *display, int width, int height) { @@ -556,6 +562,7 @@ wayland_compositor_create(struct wl_display *display, int width, int height) if (c->parent.wl_source == NULL) return NULL; + c->base.destroy = wayland_destroy; c->base.authenticate = wayland_authenticate; c->base.present = wayland_compositor_present; diff --git a/compositor/compositor-x11.c b/compositor/compositor-x11.c index 4cf9bf88..3aa24755 100644 --- a/compositor/compositor-x11.c +++ b/compositor/compositor-x11.c @@ -643,6 +643,12 @@ x11_authenticate(struct wlsc_compositor *c, uint32_t id) return dri2_authenticate((struct x11_compositor *) c, id); } +static void +x11_destroy(struct wlsc_compositor *ec) +{ + free(ec); +} + struct wlsc_compositor * x11_compositor_create(struct wl_display *display, int width, int height) { @@ -686,6 +692,7 @@ x11_compositor_create(struct wl_display *display, int width, int height) WL_EVENT_READABLE, x11_compositor_handle_event, c); + c->base.destroy = x11_destroy; c->base.authenticate = x11_authenticate; c->base.present = x11_compositor_present; diff --git a/compositor/compositor.c b/compositor/compositor.c index 28f16dd9..a09f6d90 100644 --- a/compositor/compositor.c +++ b/compositor/compositor.c @@ -1452,5 +1452,7 @@ int main(int argc, char *argv[]) wl_display_destroy(display); + ec->destroy(ec); + return 0; } diff --git a/compositor/compositor.h b/compositor/compositor.h index a41bc647..85188f9b 100644 --- a/compositor/compositor.h +++ b/compositor/compositor.h @@ -163,6 +163,7 @@ struct wlsc_compositor { uint32_t focus; + void (*destroy)(struct wlsc_compositor *ec); int (*authenticate)(struct wlsc_compositor *c, uint32_t id); void (*present)(struct wlsc_compositor *c); };