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