1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kmsg_dump.h>
3 #include <linux/spinlock.h>
4 #include <linux/console.h>
5 #include <linux/string.h>
6 #include <shared/init.h>
7 #include <shared/kern.h>
10 static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
11 enum kmsg_dump_reason reason)
13 static struct kmsg_dump_iter iter;
14 static DEFINE_SPINLOCK(lock);
15 static char line[1024];
20 /* only dump kmsg when no console is available */
21 if (!console_trylock())
24 for_each_console(con) {
25 if(strcmp(con->name, "tty") == 0 &&
26 (con->flags & (CON_ENABLED | CON_CONSDEV)) != 0) {
36 if (!spin_trylock_irqsave(&lock, flags))
39 kmsg_dump_rewind(&iter);
41 printf("kmsg_dump:\n");
42 while (kmsg_dump_get_line(&iter, true, line, sizeof(line), &len)) {
47 spin_unlock_irqrestore(&lock, flags);
50 static struct kmsg_dumper kmsg_dumper = {
51 .dump = kmsg_dumper_stdout
54 int __init kmsg_dumper_stdout_init(void)
56 return kmsg_dump_register(&kmsg_dumper);
59 __uml_postsetup(kmsg_dumper_stdout_init);