From 3027a6755ffdc46a1d8a1be010c509c696b32005 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 30 May 2021 11:12:47 +0200 Subject: [PATCH] Adjust logic in finding system consoles for progress/debug output By default, Linux gives us /dev/console for output. This is a pseudo device that uses the same actual device as the last console=foo listed in /proc/cmdline. The last one listed is the main console, which is also the *first* one listed in /sys/class/tty/console/active, so we skip that when we check for system consoles to avoid duplicating output. The getty code in tty.c currently has its own handling of @console, which we keep for now. Ideally, however, the code should be merged. Signed-off-by: Joachim Wiberg --- src/helpers.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index f5913a2d..912c17e5 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -75,9 +75,16 @@ static const char *color[] = STATUS_CLASS; */ #define MAX_CONS 3 -static char *consoles[MAX_CONS]; -static int fds[MAX_CONS]; -static int num_cons = 0; +/* + * Linux gives us stdio using /dev/console by default. This is the + * first one listed in /sys/class/tty/console/active so we don't need + * to register that again. + * + * NOTE: the getty @console is handled separately in tty.c, for now. + */ +static char *consoles[MAX_CONS] = { "/dev/console" }; +static int fds[MAX_CONS] = { 2 }; +static int num_cons = 1; /* * System default console is always the first @@ -124,6 +131,14 @@ static void add_console(char *cons) num_cons++; } +/* + * The main console is the first listed in /sys/class/tty/console/active + * we already have that open from the kernel as /dev/console, which is + * all we need to display progress and debug messages. If there are any + * more we add them as secondary consoles for displaying progress etc. + * + * The getty code in tty.c is separate from this, for now. + */ static void find_active_consoles(void) { char *cons, *ptr, *tok; @@ -145,10 +160,9 @@ static void find_active_consoles(void) cons = chomp(ptr); _d("Using these system consoles: %s", cons); - while ((tok = strtok(cons, " \t"))) { - cons = NULL; + strtok(cons, " \t"); + while ((tok = strtok(NULL, " \t"))) add_console(tok); - } } void console_init(void)