Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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]; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12 | struct console *con; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13 | size_t len = 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14 | |
| 15 | /* only dump kmsg when no console is available */ |
| 16 | if (!console_trylock()) |
| 17 | return; |
| 18 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 19 | for_each_console(con) |
| 20 | break; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | |
| 22 | console_unlock(); |
| 23 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 24 | if (con) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 25 | return; |
| 26 | |
| 27 | printf("kmsg_dump:\n"); |
| 28 | while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) { |
| 29 | line[len] = '\0'; |
| 30 | printf("%s", line); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | static struct kmsg_dumper kmsg_dumper = { |
| 35 | .dump = kmsg_dumper_stdout |
| 36 | }; |
| 37 | |
| 38 | int __init kmsg_dumper_stdout_init(void) |
| 39 | { |
| 40 | return kmsg_dump_register(&kmsg_dumper); |
| 41 | } |
| 42 | |
| 43 | __uml_postsetup(kmsg_dumper_stdout_init); |