Re: [PATCH] printk: handle blank console arguments passed in.
From: Sergey Senozhatsky
Date: Thu Oct 08 2020 - 01:52:49 EST
On (20/10/08 01:29), Sergey Senozhatsky wrote:
> On (20/10/07 08:57), Guenter Roeck wrote:
> > On 10/7/20 5:30 AM, Sergey Senozhatsky wrote:
>
> [..]
>
> > I can see to options: Link /dev/console to /dev/null if there is no console,
> > or do something like
> >
> > if (IS_ERR(file)) {
> > pr_warn("Warning: unable to open an initial console.\n");
> > file = filp_open("/dev/null", O_RDWR, 0);
> > if (IS_ERR(file))
> > return;
> > }
>
> As far as I can tell, /dev/null does not exist yet on this stage
> (at least not in my system). But generally the idea looks interesting.
Hmm. How about this. console= is undocumented and unspecified - it
may work sometimes or it may kill the system (and theoretically even
corrupt some files, depending on what fd 1 and fd 2 point to). So
maybe we can document console= and handle it in printk, rather than
somewhere deep in init/main.c
IOW add one more flag (yeah, I know) and set it when console_setup()
sees console= boot param. The idea is allow console registration,
but all consoles should be disabled (cleared CON_ENABLED bit). This
would be easier to document, at least.
Schematically:
---
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 929e86a01148..b71ff9d87693 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -281,6 +281,7 @@ static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
static int preferred_console = -1;
static bool has_preferred_console;
+static bool mute_consoles = false;
int console_set_on_cmdline;
EXPORT_SYMBOL(console_set_on_cmdline);
@@ -2141,6 +2142,9 @@ static int __add_preferred_console(char *name, int idx, char *options,
struct console_cmdline *c;
int i;
+ if (mute_consoles)
+ return;
+
/*
* See if this tty is not yet registered, and
* if we have a slot free.
@@ -2189,6 +2193,11 @@ static int __init console_setup(char *str)
char *s, *options, *brl_options = NULL;
int idx;
+ if (str[0] == 0) {
+ mute_consoles = true;
+ return 0;
+ }
+
if (_braille_console_setup(&str, &brl_options))
return 1;
@@ -2630,6 +2639,9 @@ EXPORT_SYMBOL(console_stop);
void console_start(struct console *console)
{
+ if (mute_consoles)
+ return;
+
console_lock();
console->flags |= CON_ENABLED;
console_unlock();
@@ -2811,6 +2823,9 @@ void register_console(struct console *newcon)
console_drivers->next = newcon;
}
+ if (mute_consoles)
+ newcon->flags &= ~CON_ENABLED;
+
if (newcon->flags & CON_EXTENDED)
nr_ext_console_drivers++;