kmsg_dump.c 827 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. struct console *con;
  12. size_t len = 0;
  13. /* only dump kmsg when no console is available */
  14. if (!console_trylock())
  15. return;
  16. for_each_console(con)
  17. break;
  18. console_unlock();
  19. if (con)
  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);