logo

inaban

Distrustful Wayland Compositor (inspired by XMonad and dwm)
commit: ad088a4378b49acae93549c0eef608628aaf88ca
parent 485a8f1da1b376a3918b300956da5569ff081ce7
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri,  4 Dec 2020 02:01:28 +0100

Improve error handling

Diffstat:

Minaban.c59++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 42 insertions(+), 17 deletions(-)

diff --git a/inaban.c b/inaban.c @@ -619,6 +619,7 @@ main(int argc, char *argv[]) wlr_log_init(WLR_DEBUG, NULL); char *startup_cmdv[] = {NULL}; int startup_cmdc = 0; + int ret = 0; struct wlr_server_decoration_manager *server_decoration_manager = NULL; @@ -649,18 +650,18 @@ main(int argc, char *argv[]) return 0; } - /* The Wayland display is managed by libwayland. It handles accepting - * clients from the Unix socket, manging Wayland globals, and so on. */ server.wl_display = wl_display_create(); - /* The backend is a wlroots feature which abstracts the underlying input and - * output hardware. The autocreate option will choose the most suitable - * backend based on the current environment, such as opening an X11 window - * if an X11 server is running. The NULL argument here optionally allows you - * to pass in a custom renderer if wlr_renderer doesn't meet your needs. The - * backend uses the renderer, for example, to fall back to software cursors - * if the backend does not support hardware cursors (some older GPUs - * don't). */ + if (!server.wl_display) { + wlr_log(WLR_ERROR, "Cannot allocate a Wayland display"); + return 1; + } + server.backend = wlr_backend_autocreate(server.wl_display, NULL); + if (!server.backend) { + wlr_log(WLR_ERROR, "Unable to create the wlroots backend"); + ret = 1; + goto end; + } /* If we don't provide a renderer, autocreate makes a GLES2 renderer for us. * The renderer is responsible for defining the various pixel formats it @@ -672,12 +673,26 @@ main(int argc, char *argv[]) * necessary for clients to allocate surfaces and the data device manager * handles the clipboard. Each of these wlroots interfaces has room for you * to dig your fingers in and play with their behavior if you want. */ - wlr_compositor_create(server.wl_display, server.renderer); - wlr_data_device_manager_create(server.wl_display); + if(!wlr_compositor_create(server.wl_display, server.renderer)) { + wlr_log(WLR_ERROR, "Unable to create the wlroots compositor"); + ret = 1; + goto end; + } + + if(!wlr_data_device_manager_create(server.wl_display)) { + wlr_log(WLR_ERROR, "Unable to create the data device manager"); + ret = 1; + goto end; + } /* Creates an output layout, which a wlroots utility for working with an * arrangement of screens in a physical layout. */ server.output_layout = wlr_output_layout_create(); + if(!server.output_layout) { + wlr_log(WLR_ERROR, "Unable to create output layout"); + ret = 1; + goto end; + } /* Configure a listener to be notified when new outputs are available on the * backend. */ @@ -700,7 +715,8 @@ main(int argc, char *argv[]) if(!server_decoration_manager) { wlr_log(WLR_ERROR, "Unable to create the server decoration manager"); - return 1; + ret = 1; + goto end; } wlr_server_decoration_manager_set_default_mode(server_decoration_manager, @@ -753,6 +769,11 @@ main(int argc, char *argv[]) server.new_input.notify = server_new_input; wl_signal_add(&server.backend->events.new_input, &server.new_input); server.seat = wlr_seat_create(server.wl_display, "seat0"); + if(!server.seat) { + wlr_log_errno(WLR_ERROR, "Unable to create wlroots seat"); + ret = 1; + goto end; + } server.request_cursor.notify = seat_request_cursor; wl_signal_add(&server.seat->events.request_set_cursor, &server.request_cursor); @@ -760,17 +781,21 @@ main(int argc, char *argv[]) const char *socket = wl_display_add_socket_auto(server.wl_display); if(!socket) { + wlr_log_errno(WLR_ERROR, "Unable to open Wayland socket"); wlr_backend_destroy(server.backend); - return 1; + ret = 1; + goto end; } /* Start the backend. This will enumerate outputs and inputs, become the DRM * master, etc */ if(!wlr_backend_start(server.backend)) { + wlr_log(WLR_ERROR, "Unable to start the wlroots backend"); wlr_backend_destroy(server.backend); wl_display_destroy(server.wl_display); - return 1; + ret = 1; + goto end; } /* Set the WAYLAND_DISPLAY environment variable to our socket and run the @@ -791,8 +816,8 @@ main(int argc, char *argv[]) wlr_log(WLR_INFO, "Running Wayland compositor on WAYLAND_DISPLAY=%s", socket); wl_display_run(server.wl_display); - /* Once wl_display_run returns, we shut down the server. */ +end: wl_display_destroy_clients(server.wl_display); wl_display_destroy(server.wl_display); - return 0; + return ret; }