From: Ray Strode Date: Thu, 28 Dec 2023 13:03:03 +0000 (-0500) Subject: ply-console-viewer: Handle fonts failing to load better X-Git-Tag: 24.004.60~18^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f281978ce8835624e6d5e45a5ed72f95f2de23b8;p=thirdparty%2Fplymouth.git ply-console-viewer: Handle fonts failing to load better Right now we divide by zero if the font metrics can't be determined and tank. This commit attempts to detect the situation and fall back to using kernel fb console in that case. --- diff --git a/src/libply-splash-graphics/ply-console-viewer.c b/src/libply-splash-graphics/ply-console-viewer.c index dbcf3eca..c60214e3 100644 --- a/src/libply-splash-graphics/ply-console-viewer.c +++ b/src/libply-splash-graphics/ply-console-viewer.c @@ -21,6 +21,7 @@ #include #include "ply-label.h" +#include "ply-logger.h" #include "ply-array.h" #include "ply-pixel-display.h" #include "ply-image.h" @@ -56,9 +57,39 @@ struct _ply_console_viewer static void update_console_messages (ply_console_viewer_t *console_viewer); static void on_terminal_emulator_output (ply_console_viewer_t *console_viewer); -bool ply_console_viewer_preferred (void) +bool +ply_console_viewer_preferred (void) { - return !ply_kernel_command_line_has_argument ("plymouth.prefer-fbcon"); + static enum { PLY_CONSOLE_VIEWER_PREFERENCE_UNKNOWN = -1, + PLY_CONSOLE_VIEWER_PREFERENCE_NO_VIEWER, + PLY_CONSOLE_VIEWER_PREFERENCE_VIEWER } preference = PLY_CONSOLE_VIEWER_PREFERENCE_UNKNOWN; + ply_label_t *label = NULL; + + if (preference != PLY_CONSOLE_VIEWER_PREFERENCE_UNKNOWN) + goto out; + + if (ply_kernel_command_line_has_argument ("plymouth.prefer-fbcon")) { + ply_trace ("Not using console viewer because plymouth.prefer-fbcon is on kernel command line"); + preference = PLY_CONSOLE_VIEWER_PREFERENCE_NO_VIEWER; + goto out; + } + + label = ply_label_new (); + ply_label_set_text (label, " "); + + if (ply_label_get_width (label) <= 1 || ply_label_get_height (label) <= 1) { + ply_trace ("Not using console viewer because text renderering isn't working"); + preference = PLY_CONSOLE_VIEWER_PREFERENCE_NO_VIEWER; + goto out; + } else { + ply_trace ("Using console viewer instead of kernel framebuffer console"); + preference = PLY_CONSOLE_VIEWER_PREFERENCE_NO_VIEWER; + goto out; + } + +out: + ply_label_free (label); + return (bool) preference; } ply_console_viewer_t *