Skip to content

Commit a91bd62

Browse files
pmladektorvalds
authored andcommitted
Revert "init/console: Use ttynull as a fallback when there is no console"
This reverts commit 757055a. The commit caused that ttynull was used as the default console on several systems[1][2][3]. As a result, the console was blank even when a better alternative existed. It happened when there was no console configured on the command line and ttynull_init() was the first initcall calling register_console(). Or it happened when /dev/ did not exist when console_on_rootfs() was called. It was not able to open /dev/console even though a console driver was registered. It tried to add ttynull console but it obviously did not help. But ttynull became the preferred console and was used by /dev/console when it was available later. The commit tried to fix a historical problem that have been there for ages. The primary motivation was the commit 3cffa06 ("printk/console: Allow to disable console output by using console="" or console=null"). It provided a clean solution for a workaround that was widely used and worked only by chance. This revert causes that the console="" or console=null command line options will again work only by chance. These options will cause that a particular console will be preferred and the default (tty) ones will not get enabled. There will be no console registered at all. As a result there won't be stdin, stdout, and stderr for the init process. But it worked exactly this way even before. The proper solution has to fulfill many conditions: + Register ttynull only when explicitly required or as the ultimate fallback. + ttynull should get associated with /dev/console but it must not become preferred console when used as a fallback. Especially, it must still be possible to replace it by a better console later. Such a change requires clean up of the register_console() code. Otherwise, it would be even harder to follow. Especially, the use of has_preferred_console and CON_CONSDEV flag is tricky. The clean up is risky. The ordering of consoles is not well defined. And any changes tend to break existing user settings. Do the revert at the least risky solution for now. [1] https://lore.kernel.org/linux-kselftest/[email protected]/ [2] https://lore.kernel.org/lkml/[email protected]/ [3] https://patchwork.ozlabs.org/project/linux-um/patch/[email protected]/ Reported-by: Andy Shevchenko <[email protected]> Reported-by: Vineet Gupta <[email protected]> Reported-by: Thomas Meyer <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Acked-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c4cc3b1 commit a91bd62

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

drivers/tty/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,20 @@ config MIPS_EJTAG_FDC_KGDB_CHAN
401401
help
402402
FDC channel number to use for KGDB.
403403

404+
config NULL_TTY
405+
tristate "NULL TTY driver"
406+
help
407+
Say Y here if you want a NULL TTY which simply discards messages.
408+
409+
This is useful to allow userspace applications which expect a console
410+
device to work without modifications even when no console is
411+
available or desired.
412+
413+
In order to use this driver, you should redirect the console to this
414+
TTY, or boot the kernel with console=ttynull.
415+
416+
If unsure, say N.
417+
404418
config TRACE_ROUTER
405419
tristate "Trace data router for MIPI P1149.7 cJTAG standard"
406420
depends on TRACE_SINK

drivers/tty/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
obj-$(CONFIG_TTY) += tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o \
33
tty_buffer.o tty_port.o tty_mutex.o \
44
tty_ldsem.o tty_baudrate.o tty_jobctrl.o \
5-
n_null.o ttynull.o
5+
n_null.o
66
obj-$(CONFIG_LEGACY_PTYS) += pty.o
77
obj-$(CONFIG_UNIX98_PTYS) += pty.o
88
obj-$(CONFIG_AUDIT) += tty_audit.o
@@ -25,6 +25,7 @@ obj-$(CONFIG_ISI) += isicom.o
2525
obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
2626
obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
2727
obj-$(CONFIG_NOZOMI) += nozomi.o
28+
obj-$(CONFIG_NULL_TTY) += ttynull.o
2829
obj-$(CONFIG_ROCKETPORT) += rocket.o
2930
obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
3031
obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o

drivers/tty/ttynull.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
/*
33
* Copyright (C) 2019 Axis Communications AB
44
*
5-
* The console is useful for userspace applications which expect a console
6-
* device to work without modifications even when no console is available
7-
* or desired.
8-
*
9-
* In order to use this driver, you should redirect the console to this
10-
* TTY, or boot the kernel with console=ttynull.
11-
*
125
* Based on ttyprintk.c:
136
* Copyright (C) 2010 Samo Pogacnik
147
*/
@@ -66,17 +59,6 @@ static struct console ttynull_console = {
6659
.device = ttynull_device,
6760
};
6861

69-
void __init register_ttynull_console(void)
70-
{
71-
if (!ttynull_driver)
72-
return;
73-
74-
if (add_preferred_console(ttynull_console.name, 0, NULL))
75-
return;
76-
77-
register_console(&ttynull_console);
78-
}
79-
8062
static int __init ttynull_init(void)
8163
{
8264
struct tty_driver *driver;

include/linux/console.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,9 @@ extern int braille_register_console(struct console *, int index,
186186
extern int braille_unregister_console(struct console *);
187187
#ifdef CONFIG_TTY
188188
extern void console_sysfs_notify(void);
189-
extern void register_ttynull_console(void);
190189
#else
191190
static inline void console_sysfs_notify(void)
192191
{ }
193-
static inline void register_ttynull_console(void)
194-
{ }
195192
#endif
196193
extern bool console_suspend_enabled;
197194

init/main.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,14 +1480,8 @@ void __init console_on_rootfs(void)
14801480
struct file *file = filp_open("/dev/console", O_RDWR, 0);
14811481

14821482
if (IS_ERR(file)) {
1483-
pr_err("Warning: unable to open an initial console. Fallback to ttynull.\n");
1484-
register_ttynull_console();
1485-
1486-
file = filp_open("/dev/console", O_RDWR, 0);
1487-
if (IS_ERR(file)) {
1488-
pr_err("Warning: Failed to add ttynull console. No stdin, stdout, and stderr for the init process!\n");
1489-
return;
1490-
}
1483+
pr_err("Warning: unable to open an initial console.\n");
1484+
return;
14911485
}
14921486
init_dup(file);
14931487
init_dup(file);

0 commit comments

Comments
 (0)