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