stderr_console.c 1.6 KB

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