blob: 911539293871d271ed306c36fd1b113f6acc9203 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
Jeff Dike6edb0862006-06-30 01:55:55 -070011 * boot process it becomes the default console.
Jeff Dike730760e2006-09-29 01:58:50 -070012 *
13 * Initialized at init time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15static int use_stderr_console = 0;
16
17static void stderr_console_write(struct console *console, const char *string,
18 unsigned len)
19{
20 generic_write(2 /* stderr */, string, len, NULL);
21}
22
23static struct console stderr_console = {
Jeff Dikeda00d9a2005-06-08 15:48:01 -070024 .name = "stderr",
25 .write = stderr_console_write,
26 .flags = CON_PRINTBUFFER,
Linus Torvalds1da177e2005-04-16 15:20:36 -070027};
28
29static int __init stderr_console_init(void)
30{
31 if (use_stderr_console)
32 register_console(&stderr_console);
33 return 0;
34}
35console_initcall(stderr_console_init);
36
37static 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);
Jeff Dike6edb0862006-06-30 01:55:55 -070045
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 */
54static int __init unregister_stderr(void)
55{
56 unregister_console(&stderr_console);
57
58 return 0;
59}
60
61__initcall(unregister_stderr);