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