xref: /openbmc/linux/arch/um/drivers/stderr_console.c (revision a8da474e)
1 #include <linux/kernel.h>
2 #include <linux/init.h>
3 #include <linux/console.h>
4 
5 #include "chan_user.h"
6 
7 /* ----------------------------------------------------------------------------- */
8 /* trivial console driver -- simply dump everything to stderr                    */
9 
10 /*
11  * Don't register by default -- as this registers very early in the
12  * boot process it becomes the default console.
13  *
14  * Initialized at init time.
15  */
16 static int use_stderr_console = 0;
17 
18 static void stderr_console_write(struct console *console, const char *string,
19 				 unsigned len)
20 {
21 	generic_write(2 /* stderr */, string, len, NULL);
22 }
23 
24 static struct console stderr_console = {
25 	.name		= "stderr",
26 	.write		= stderr_console_write,
27 	.flags		= CON_PRINTBUFFER,
28 };
29 
30 static int __init stderr_console_init(void)
31 {
32 	if (use_stderr_console)
33 		register_console(&stderr_console);
34 	return 0;
35 }
36 console_initcall(stderr_console_init);
37 
38 static int stderr_setup(char *str)
39 {
40 	if (!str)
41 		return 0;
42 	use_stderr_console = simple_strtoul(str,&str,0);
43 	return 1;
44 }
45 __setup("stderr=", stderr_setup);
46 
47 /* The previous behavior of not unregistering led to /dev/console being
48  * impossible to open.  My FC5 filesystem started having init die, and the
49  * system panicing because of this.  Unregistering causes the real
50  * console to become the default console, and /dev/console can then be
51  * opened.  Making this an initcall makes this happen late enough that
52  * there is no added value in dumping everything to stderr, and the
53  * normal console is good enough to show you all available output.
54  */
55 static int __init unregister_stderr(void)
56 {
57 	unregister_console(&stderr_console);
58 
59 	return 0;
60 }
61 
62 __initcall(unregister_stderr);
63