stderr_console.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. static int use_stderr_console = 0;
  11. static void stderr_console_write(struct console *console, const char *string,
  12. unsigned len)
  13. {
  14. generic_write(2 /* stderr */, string, len, NULL);
  15. }
  16. static struct console stderr_console = {
  17. .name = "stderr",
  18. .write = stderr_console_write,
  19. .flags = CON_PRINTBUFFER,
  20. };
  21. static int __init stderr_console_init(void)
  22. {
  23. if (use_stderr_console)
  24. register_console(&stderr_console);
  25. return 0;
  26. }
  27. console_initcall(stderr_console_init);
  28. static int stderr_setup(char *str)
  29. {
  30. if (!str)
  31. return 0;
  32. use_stderr_console = simple_strtoul(str,&str,0);
  33. return 1;
  34. }
  35. __setup("stderr=", stderr_setup);
  36. /* The previous behavior of not unregistering led to /dev/console being
  37. * impossible to open. My FC5 filesystem started having init die, and the
  38. * system panicing because of this. Unregistering causes the real
  39. * console to become the default console, and /dev/console can then be
  40. * opened. Making this an initcall makes this happen late enough that
  41. * there is no added value in dumping everything to stderr, and the
  42. * normal console is good enough to show you all available output.
  43. */
  44. static int __init unregister_stderr(void)
  45. {
  46. unregister_console(&stderr_console);
  47. return 0;
  48. }
  49. __initcall(unregister_stderr);