From 3361639b7b44c7c0cb900dc6f5acb626e28b3503 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 30 Jul 2012 16:56:57 +0300 Subject: [PATCH] compositor: do clean-up on init failure Simply exit(1)'ing the program will leave the VT unusable, since DRM backend's clean-up does not run. After a backend has been initialised, prefer jumping to clean-up instead of directly exiting. This fixes the case where 'weston-launch -- -i 5' would leave the console unusable. Signed-off-by: Pekka Paalanen --- src/compositor.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 746ff856..c659527a 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -3489,14 +3489,16 @@ int main(int argc, char *argv[]) ec = backend_init(display, argc, argv, config_file); if (ec == NULL) { - weston_log("failed to create compositor\n"); + weston_log("fatal: failed to create compositor\n"); exit(EXIT_FAILURE); } for (i = 1; argv[i]; i++) - weston_log("unhandled option: %s\n", argv[i]); - if (argv[1]) - exit(EXIT_FAILURE); + weston_log("fatal: unhandled option: %s\n", argv[i]); + if (argv[1]) { + ret = EXIT_FAILURE; + goto out; + } free(config_file); @@ -3508,25 +3510,32 @@ int main(int argc, char *argv[]) module_init = load_module("xwayland.so", "weston_xserver_init", &xserver_module); - if (module_init && module_init(ec) < 0) - exit(EXIT_FAILURE); + if (module_init && module_init(ec) < 0) { + ret = EXIT_FAILURE; + goto out; + } if (!shell) shell = "desktop-shell.so"; module_init = load_module(shell, "shell_init", &shell_module); - if (!module_init || module_init(ec) < 0) - exit(EXIT_FAILURE); + if (!module_init || module_init(ec) < 0) { + ret = EXIT_FAILURE; + goto out; + } module_init = NULL; if (module) module_init = load_module(module, "module_init", NULL); - if (module_init && module_init(ec) < 0) - exit(EXIT_FAILURE); + if (module_init && module_init(ec) < 0) { + ret = EXIT_FAILURE; + goto out; + } if (wl_display_add_socket(display, socket_name)) { - weston_log("failed to add socket: %m\n"); - exit(EXIT_FAILURE); + weston_log("fatal: failed to add socket: %m\n"); + ret = EXIT_FAILURE; + goto out; } weston_compositor_dpms_on(ec); @@ -3536,6 +3545,7 @@ int main(int argc, char *argv[]) else ret = EXIT_FAILURE; +out: /* prevent further rendering while shutting down */ ec->state = WESTON_COMPOSITOR_SLEEPING;