blob: d07a97f8b9945343791d4fb32c9ad0bf5c7d9df2 [file] [log] [blame]
Jeff Dikee16f5352007-06-08 13:46:54 -07001#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#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 Arlottb60745b2007-10-20 01:23:03 +020011 * Don't register by default -- as this registers very early in the
Jeff Dike6edb0862006-06-30 01:55:55 -070012 * boot process it becomes the default console.
Jeff Dike730760e2006-09-29 01:58:50 -070013 *
14 * Initialized at init time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 */
16static int use_stderr_console = 0;
17
18static void stderr_console_write(struct console *console, const char *string,
19 unsigned len)
20{
21 generic_write(2 /* stderr */, string, len, NULL);
22}
23
24static struct console stderr_console = {
Jeff Dikeda00d9a2005-06-08 15:48:01 -070025 .name = "stderr",
26 .write = stderr_console_write,
27 .flags = CON_PRINTBUFFER,
Linus Torvalds1da177e2005-04-16 15:20:36 -070028};
29
30static int __init stderr_console_init(void)
31{
32 if (use_stderr_console)
33 register_console(&stderr_console);
34 return 0;
35}
36console_initcall(stderr_console_init);
37
38static 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 Dike6edb0862006-06-30 01:55:55 -070046
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 */
55static int __init unregister_stderr(void)
56{
57 unregister_console(&stderr_console);
58
59 return 0;
60}
61
62__initcall(unregister_stderr);