From 2dc6aa9e44d187ee2933b3f8fc438d24eb060ed9 Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Fri, 2 Aug 2024 07:56:28 -0400 Subject: [PATCH 1/3] ply-device-manager: Don't log an error when /sys/class/tty/console/active is empty This is possible on some kernels that were built with CONFIG_NULL_TTY enabled, and were booted with console=ttynull /sys/class/tty/console/active is empty in this case, so the file being empty is not always an error worth logging --- src/libply-splash-core/ply-device-manager.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libply-splash-core/ply-device-manager.c b/src/libply-splash-core/ply-device-manager.c index 1f41e1b2..bbfbd50d 100644 --- a/src/libply-splash-core/ply-device-manager.c +++ b/src/libply-splash-core/ply-device-manager.c @@ -974,7 +974,9 @@ add_consoles_from_file (ply_device_manager_t *manager, contents_length = read (fd, contents, sizeof(contents) - 1); if (contents_length <= 0) { - ply_trace ("couldn't read it: %m"); + if (contents_length < 0) + ply_trace ("couldn't read it: %m"); + close (fd); return false; } From 7847f49ec84a9e30f7a83b688f774c90d971944a Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Fri, 2 Aug 2024 07:59:14 -0400 Subject: [PATCH 2/3] ply-utils: Add ply_get_primary_kernel_console_type () --- src/libply/ply-utils.c | 28 ++++++++++++++++++++++++++++ src/libply/ply-utils.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index d6d127f1..155459dc 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -1259,6 +1259,34 @@ ply_kernel_command_line_override (const char *command_line) kernel_command_line_is_set = true; } +char * +ply_get_primary_kernel_console_type (void) +{ + int fd; + int len; + char proc_consoles[4096] = ""; + size_t return_length; + + if (ply_file_exists ("/proc/consoles")) { + ply_trace ("opening /proc/consoles"); + + fd = open ("/proc/consoles", O_RDONLY); + len = read (fd, proc_consoles, sizeof(proc_consoles)); + close (fd); + + /* The device type for /dev/ttyS0 is "ttyS". + * for /dev/ttynull it is "ttynull", which appears as "ttynull0" in /proc/consoles. Exclude any numbers at the end. + */ + for (return_length = 0; return_length < len; return_length++) { + /* Read until the next digit or space, the digit should be first */ + if (isdigit (proc_consoles[return_length]) || isspace (proc_consoles[return_length])) + return strndup (proc_consoles, return_length); + } + } + + return NULL; +} + double ply_strtod (const char *str) { char *old_locale; diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index 86d66384..1ee31960 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -176,6 +176,8 @@ bool ply_kernel_command_line_has_argument (const char *argument); void ply_kernel_command_line_override (const char *command_line); char *ply_kernel_command_line_get_key_value (const char *key); +char *ply_get_primary_kernel_console_type (void); + double ply_strtod (const char *str); bool ply_is_secure_boot_enabled (void); From f2d0f87b9993a176b3efc633a80420d3f296f325 Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Fri, 2 Aug 2024 08:00:10 -0400 Subject: [PATCH 3/3] main: Assume graphical splash when the active kernel console is /dev/ttynull. --- src/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 33fe51e0..9c98bedf 100644 --- a/src/main.c +++ b/src/main.c @@ -884,6 +884,19 @@ sh_is_init (state_t *state) return result; } +static bool +kernel_console_is_ttynull (void) +{ + char *kernel_console = ply_get_primary_kernel_console_type (); + + /* If the primary console is ttynull, the kernel console is virtual. + */ + if (strcmp (kernel_console, "ttynull") == 0) + return true; + + return false; +} + static bool plymouth_should_show_default_splash (state_t *state) { @@ -925,7 +938,7 @@ plymouth_should_show_default_splash (state_t *state) } if (state->should_force_default_splash) { - ply_trace ("using default splash because kernel command line has option \"plymouth.graphical\""); + ply_trace ("using default splash because forced by \"plymouth.graphical\" or no active kernel console"); return true; } @@ -2457,7 +2470,7 @@ main (int argc, signal (SIGSEGV, on_crash); signal (SIGFPE, on_crash); - if (graphical_boot || ply_kernel_command_line_has_argument ("plymouth.graphical")) { + if (graphical_boot || ply_kernel_command_line_has_argument ("plymouth.graphical") || kernel_console_is_ttynull ()) { state.should_force_default_splash = true; ignore_serial_consoles = true; }