// SPDX-License-Identifier: GPL-2.01#include <linux/kernel.h>2#include <linux/init.h>3#include <linux/console.h>45#include "chan_user.h"67/* ----------------------------------------------------------------------------- */8/* trivial console driver -- simply dump everything to stderr */910/*11* Don't register by default -- as this registers very early in the12* boot process it becomes the default console.13*14* Initialized at init time.15*/16static int use_stderr_console = 0;1718static void stderr_console_write(struct console *console, const char *string,19unsigned len)20{21generic_write(2 /* stderr */, string, len, NULL);22}2324static struct console stderr_console = {25.name = "stderr",26.write = stderr_console_write,27.flags = CON_PRINTBUFFER,28};2930static int __init stderr_console_init(void)31{32if (use_stderr_console)33register_console(&stderr_console);34return 0;35}36console_initcall(stderr_console_init);3738static int stderr_setup(char *str)39{40if (!str)41return 0;42use_stderr_console = simple_strtoul(str,&str,0);43return 1;44}45__setup("stderr=", stderr_setup);4647/* The previous behavior of not unregistering led to /dev/console being48* impossible to open. My FC5 filesystem started having init die, and the49* system panicing because of this. Unregistering causes the real50* console to become the default console, and /dev/console can then be51* opened. Making this an initcall makes this happen late enough that52* there is no added value in dumping everything to stderr, and the53* normal console is good enough to show you all available output.54*/55static int __init unregister_stderr(void)56{57unregister_console(&stderr_console);5859return 0;60}6162__initcall(unregister_stderr);636465