]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-console-viewer: Handle fonts failing to load better
authorRay Strode <rstrode@redhat.com>
Thu, 28 Dec 2023 13:03:03 +0000 (08:03 -0500)
committerRay Strode <rstrode@redhat.com>
Thu, 28 Dec 2023 13:59:25 +0000 (08:59 -0500)
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.

src/libply-splash-graphics/ply-console-viewer.c

index dbcf3eca627f24c3b7caa66dfc8e9b5fa1f1f1d9..c60214e39cac641453fb439f26f5740902c05f90 100644 (file)
@@ -21,6 +21,7 @@
 #include <assert.h>
 
 #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 *