stderr_console.c 1.6 KB

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