diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index a45d423ad10f..98ac8a394c88 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -383,7 +383,23 @@ config NULL_TTY available or desired. In order to use this driver, you should redirect the console to this - TTY, or boot the kernel with console=ttynull. + TTY, boot the kernel with console=ttynull, or enable + CONFIG_NULL_TTY_CONSOLE. + + If unsure, say N. + +config NULL_TTY_CONSOLE + bool "Supports /dev/ttynull as a console automatically" + depends on NULL_TTY && !VT_CONSOLE + help + Say Y here if you want the NULL TTY to be used as a /dev/console + device. + + This is useful for userspace applications that expect a working + console device, without changing the kernel boot options, such as a + distribuition or environment that historically had CONFIG_VT_CONSOLE + enabled, and have now disabled it, but still need /dev/console to be + working for userspace applications. If unsure, say N. diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index dddb15f48d59..c1554a789de8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3712,6 +3712,11 @@ void __init console_init(void) initcall_t call; initcall_entry_t *ce; +#ifdef CONFIG_NULL_TTY_CONSOLE + if (!strstr(boot_command_line, "console=")) + add_preferred_console("ttynull", 0, NULL); +#endif + /* Setup the default TTY line discipline. */ n_tty_init();