Jeff Dike | e16f535 | 2007-06-08 13:46:54 -0700 | [diff] [blame] | 1 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* |
Simon Arlott | b60745b | 2007-10-20 01:23:03 +0200 | [diff] [blame] | 11 | * Don't register by default -- as this registers very early in the |
Jeff Dike | 6edb086 | 2006-06-30 01:55:55 -0700 | [diff] [blame] | 12 | * boot process it becomes the default console. |
Jeff Dike | 730760e | 2006-09-29 01:58:50 -0700 | [diff] [blame] | 13 | * |
| 14 | * Initialized at init time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 = { |
Jeff Dike | da00d9a | 2005-06-08 15:48:01 -0700 | [diff] [blame] | 25 | .name = "stderr", |
| 26 | .write = stderr_console_write, |
| 27 | .flags = CON_PRINTBUFFER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Jeff Dike | 6edb086 | 2006-06-30 01:55:55 -0700 | [diff] [blame] | 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); |