From 528566527ed13a3b183cc97741e3fcc506e628de Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 7 Apr 2026 17:11:26 +0300 Subject: [PATCH] libweston: allow calling weston_compositor_exit() early Assertions are the usual way of failing tests in the compositor code, but it means the test program cannot continue further. It would be better to save an error exit code and run the compositor to the finish, and then continue with the next test fixture. I want to force some paths in GL-renderer output initialization for a test, and fail otherwise. Calling weston_compositor_exit_with_code() crashes there though, because the frontend has not installed the exit handler yet. Skip the exit handler if it's not there. The error exit code is still saved, and will eventually bubble out of the compositor. While at it, let's document these. Signed-off-by: Pekka Paalanen --- libweston/compositor.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libweston/compositor.c b/libweston/compositor.c index 84e8999a0..b773c8e52 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -10312,7 +10312,18 @@ weston_compositor_shutdown(struct weston_compositor *ec) weston_log("BUG: layer_list is not empty after shutdown. Calls to weston_layer_fini() are missing somwhere.\n"); } -/** weston_compositor_exit_with_code +/** Instruct the compositor to exit with an error code + * + * \param compositor The compositor to tear down. + * \param exit_code The exit code to save until the frontend chooses to exit + * and maybe forward it. + * + * Only the first error code (value other than EXIT_SUCCESS) will be saved. + * It cannot later be overwritten with EXIT_SUCCESS. + * + * Otherwise this function is identical to \c weston_compositor_exit() . + * + * \sa weston_compositor_exit * \ingroup compositor */ WL_EXPORT void @@ -10750,8 +10761,11 @@ weston_compositor_destroy(struct weston_compositor *compositor) /** Instruct the compositor to exit. * * This functions does not directly destroy the compositor object, it merely - * command it to start the tear down process. It is not guaranteed that the - * tear down will happen immediately. + * forwards the call to the frontend to start the tear down process. + * It is not guaranteed that the tear down will happen immediately. + * + * If the frontend is not yet listening to exit calls, this function does + * nothing. * * \param compositor The compositor to tear down. * @@ -10760,7 +10774,8 @@ weston_compositor_destroy(struct weston_compositor *compositor) WL_EXPORT void weston_compositor_exit(struct weston_compositor *compositor) { - compositor->exit(compositor); + if (compositor->exit) + compositor->exit(compositor); } /** Return the user data stored in the compositor.