stderr_console.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/console.h>
  5. #include "chan_user.h"
  6. /* ----------------------------------------------------------------------------- */
  7. /* trivial console driver -- simply dump everything to stderr */
  8. /*
  9. * Don't register by default -- as this registers very early in the
  10. * boot process it becomes the default console.
  11. *
  12. * Initialized at init time.
  13. */
  14. static int use_stderr_console = 0;
  15. static void stderr_console_write(struct console *console, const char *string,
  16. unsigned len)
  17. {
  18. generic_write(2 /* stderr */, string, len, NULL);
  19. }
  20. static struct console stderr_console = {
  21. .name = "stderr",
  22. .write = stderr_console_write,
  23. .flags = CON_PRINTBUFFER,
  24. };
  25. static int __init stderr_console_init(void)
  26. {
  27. if (use_stderr_console)
  28. register_console(&stderr_console);
  29. return 0;
  30. }
  31. console_initcall(stderr_console_init);
  32. static int stderr_setup(char *str)
  33. {
  34. if (!str)
  35. return 0;
  36. use_stderr_console = simple_strtoul(str,&str,0);
  37. return 1;
  38. }
  39. __setup("stderr=", stderr_setup);
  40. /* The previous behavior of not unregistering led to /dev/console being
  41. * impossible to open. My FC5 filesystem started having init die, and the
  42. * system panicing because of this. Unregistering causes the real
  43. * console to become the default console, and /dev/console can then be
  44. * opened. Making this an initcall makes this happen late enough that
  45. * there is no added value in dumping everything to stderr, and the
  46. * normal console is good enough to show you all available output.
  47. */
  48. static int __init unregister_stderr(void)
  49. {
  50. unregister_console(&stderr_console);
  51. return 0;
  52. }
  53. __initcall(unregister_stderr);