linux/arch/um/drivers/stderr_console.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2#include <linux/kernel.h>
   3#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/*
  12 * Don't register by default -- as this registers very early in the
  13 * boot process it becomes the default console.
  14 *
  15 * Initialized at init time.
  16 */
  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 = {
  26        .name           = "stderr",
  27        .write          = stderr_console_write,
  28        .flags          = CON_PRINTBUFFER,
  29};
  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);
  47
  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);
  64