Loading...
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
8static 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
35static struct kmsg_dumper kmsg_dumper = {
36 .dump = kmsg_dumper_stdout
37};
38
39int __init kmsg_dumper_stdout_init(void)
40{
41 return kmsg_dump_register(&kmsg_dumper);
42}
43
44__uml_postsetup(kmsg_dumper_stdout_init);
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>
8#include <os.h>
9
10static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
11 enum kmsg_dump_reason reason)
12{
13 static struct kmsg_dump_iter iter;
14 static DEFINE_SPINLOCK(lock);
15 static char line[1024];
16 struct console *con;
17 unsigned long flags;
18 size_t len = 0;
19
20 /* only dump kmsg when no console is available */
21 if (!console_trylock())
22 return;
23
24 for_each_console(con) {
25 if(strcmp(con->name, "tty") == 0 &&
26 (con->flags & (CON_ENABLED | CON_CONSDEV)) != 0) {
27 break;
28 }
29 }
30
31 console_unlock();
32
33 if (con)
34 return;
35
36 if (!spin_trylock_irqsave(&lock, flags))
37 return;
38
39 kmsg_dump_rewind(&iter);
40
41 printf("kmsg_dump:\n");
42 while (kmsg_dump_get_line(&iter, true, line, sizeof(line), &len)) {
43 line[len] = '\0';
44 printf("%s", line);
45 }
46
47 spin_unlock_irqrestore(&lock, flags);
48}
49
50static struct kmsg_dumper kmsg_dumper = {
51 .dump = kmsg_dumper_stdout
52};
53
54int __init kmsg_dumper_stdout_init(void)
55{
56 return kmsg_dump_register(&kmsg_dumper);
57}
58
59__uml_postsetup(kmsg_dumper_stdout_init);