xref: /openbmc/linux/arch/um/kernel/kmsg_dump.c (revision 04a7279f)
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 
8 static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
9 				enum kmsg_dump_reason reason)
10 {
11 	static char line[1024];
12 
13 	size_t len = 0;
14 	bool con_available = false;
15 
16 	/* only dump kmsg when no console is available */
17 	if (!console_trylock())
18 		return;
19 
20 	if (console_drivers != NULL)
21 		con_available = true;
22 
23 	console_unlock();
24 
25 	if (con_available == true)
26 		return;
27 
28 	printf("kmsg_dump:\n");
29 	while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) {
30 		line[len] = '\0';
31 		printf("%s", line);
32 	}
33 }
34 
35 static struct kmsg_dumper kmsg_dumper = {
36 	.dump = kmsg_dumper_stdout
37 };
38 
39 int __init kmsg_dumper_stdout_init(void)
40 {
41 	return kmsg_dump_register(&kmsg_dumper);
42 }
43 
44 __uml_postsetup(kmsg_dumper_stdout_init);
45