blob: ecc3a58149324db4ec7dd02fa5a8eab0e3952a98 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jeff Dikee16f5352007-06-08 13:46:54 -07002#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/init.h>
4#include <linux/console.h>
5
6#include "chan_user.h"
7
8/* ----------------------------------------------------------------------------- */
9/* trivial console driver -- simply dump everything to stderr */
10
11/*
Simon Arlottb60745b2007-10-20 01:23:03 +020012 * Don't register by default -- as this registers very early in the
Jeff Dike6edb0862006-06-30 01:55:55 -070013 * boot process it becomes the default console.
Jeff Dike730760e2006-09-29 01:58:50 -070014 *
15 * Initialized at init time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
17static int use_stderr_console = 0;
18
19static void stderr_console_write(struct console *console, const char *string,
20 unsigned len)
21{
22 generic_write(2 /* stderr */, string, len, NULL);
23}
24
25static struct console stderr_console = {
Jeff Dikeda00d9a2005-06-08 15:48:01 -070026 .name = "stderr",
27 .write = stderr_console_write,
28 .flags = CON_PRINTBUFFER,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029};
30
31static int __init stderr_console_init(void)
32{
33 if (use_stderr_console)
34 register_console(&stderr_console);
35 return 0;
36}
37console_initcall(stderr_console_init);
38
39static int stderr_setup(char *str)
40{
41 if (!str)
42 return 0;
43 use_stderr_console = simple_strtoul(str,&str,0);
44 return 1;
45}
46__setup("stderr=", stderr_setup);
Jeff Dike6edb0862006-06-30 01:55:55 -070047
48/* The previous behavior of not unregistering led to /dev/console being
49 * impossible to open. My FC5 filesystem started having init die, and the
50 * system panicing because of this. Unregistering causes the real
51 * console to become the default console, and /dev/console can then be
52 * opened. Making this an initcall makes this happen late enough that
53 * there is no added value in dumping everything to stderr, and the
54 * normal console is good enough to show you all available output.
55 */
56static int __init unregister_stderr(void)
57{
58 unregister_console(&stderr_console);
59
60 return 0;
61}
62
63__initcall(unregister_stderr);