kmsg_dump.c 875 B

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