kmsg_dump.c 839 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <linux/kmsg_dump.h>
  2. #include <linux/console.h>
  3. #include <shared/init.h>
  4. #include <shared/kern.h>
  5. #include <os.h>
  6. static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
  7. enum kmsg_dump_reason reason)
  8. {
  9. static char line[1024];
  10. size_t len = 0;
  11. bool con_available = false;
  12. /* only dump kmsg when no console is available */
  13. if (!console_trylock())
  14. return;
  15. if (console_drivers != NULL)
  16. con_available = true;
  17. console_unlock();
  18. if (con_available == true)
  19. return;
  20. printf("kmsg_dump:\n");
  21. while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) {
  22. line[len] = '\0';
  23. printf("%s", line);
  24. }
  25. }
  26. static struct kmsg_dumper kmsg_dumper = {
  27. .dump = kmsg_dumper_stdout
  28. };
  29. int __init kmsg_dumper_stdout_init(void)
  30. {
  31. return kmsg_dump_register(&kmsg_dumper);
  32. }
  33. __uml_postsetup(kmsg_dumper_stdout_init);