Files

66 lines
1.4 KiB
C
Raw Permalink Normal View History

// SPDX-License-Identifier: GPL-2.0
2015-03-28 10:07:37 +01:00
#include <linux/kmsg_dump.h>
2021-03-03 11:15:14 +01:00
#include <linux/spinlock.h>
2015-03-28 10:07:37 +01:00
#include <linux/console.h>
#include <linux/string.h>
2015-03-28 10:07:37 +01:00
#include <shared/init.h>
#include <shared/kern.h>
#include <os.h>
static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
struct kmsg_dump_detail *detail)
2015-03-28 10:07:37 +01:00
{
2021-03-03 11:15:25 +01:00
static struct kmsg_dump_iter iter;
2021-03-03 11:15:14 +01:00
static DEFINE_SPINLOCK(lock);
2015-03-28 10:07:37 +01:00
static char line[1024];
2020-02-12 12:02:59 +02:00
struct console *con;
2021-03-03 11:15:14 +01:00
unsigned long flags;
2015-03-28 10:07:37 +01:00
size_t len = 0;
int cookie;
2015-03-28 10:07:37 +01:00
/*
* If no consoles are available to output crash information, dump
* the kmsg buffer to stdout.
*/
cookie = console_srcu_read_lock();
for_each_console_srcu(con) {
/*
* The ttynull console and disabled consoles are ignored
* since they cannot output. All other consoles are
* expected to output the crash information.
*/
if (strcmp(con->name, "ttynull") != 0 &&
2025-11-21 15:50:34 -03:00
console_is_usable(con, console_srcu_read_flags(con), true)) {
break;
}
}
console_srcu_read_unlock(cookie);
2020-02-12 12:02:59 +02:00
if (con)
2015-03-28 10:07:37 +01:00
return;
2021-03-03 11:15:14 +01:00
if (!spin_trylock_irqsave(&lock, flags))
return;
2021-03-03 11:15:25 +01:00
kmsg_dump_rewind(&iter);
2015-03-28 10:07:37 +01:00
printf("kmsg_dump:\n");
2021-03-03 11:15:25 +01:00
while (kmsg_dump_get_line(&iter, true, line, sizeof(line), &len)) {
2015-03-28 10:07:37 +01:00
line[len] = '\0';
printf("%s", line);
}
2021-03-03 11:15:14 +01:00
spin_unlock_irqrestore(&lock, flags);
2015-03-28 10:07:37 +01:00
}
static struct kmsg_dumper kmsg_dumper = {
.dump = kmsg_dumper_stdout
};
static int __init kmsg_dumper_stdout_init(void)
2015-03-28 10:07:37 +01:00
{
return kmsg_dump_register(&kmsg_dumper);
}
__uml_postsetup(kmsg_dumper_stdout_init);