0001
0002 #include <linux/kmsg_dump.h>
0003 #include <linux/spinlock.h>
0004 #include <linux/console.h>
0005 #include <linux/string.h>
0006 #include <shared/init.h>
0007 #include <shared/kern.h>
0008 #include <os.h>
0009
0010 static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
0011 enum kmsg_dump_reason reason)
0012 {
0013 static struct kmsg_dump_iter iter;
0014 static DEFINE_SPINLOCK(lock);
0015 static char line[1024];
0016 struct console *con;
0017 unsigned long flags;
0018 size_t len = 0;
0019
0020
0021 if (!console_trylock())
0022 return;
0023
0024 for_each_console(con) {
0025 if(strcmp(con->name, "tty") == 0 &&
0026 (con->flags & (CON_ENABLED | CON_CONSDEV)) != 0) {
0027 break;
0028 }
0029 }
0030
0031 console_unlock();
0032
0033 if (con)
0034 return;
0035
0036 if (!spin_trylock_irqsave(&lock, flags))
0037 return;
0038
0039 kmsg_dump_rewind(&iter);
0040
0041 printf("kmsg_dump:\n");
0042 while (kmsg_dump_get_line(&iter, true, line, sizeof(line), &len)) {
0043 line[len] = '\0';
0044 printf("%s", line);
0045 }
0046
0047 spin_unlock_irqrestore(&lock, flags);
0048 }
0049
0050 static struct kmsg_dumper kmsg_dumper = {
0051 .dump = kmsg_dumper_stdout
0052 };
0053
0054 int __init kmsg_dumper_stdout_init(void)
0055 {
0056 return kmsg_dump_register(&kmsg_dumper);
0057 }
0058
0059 __uml_postsetup(kmsg_dumper_stdout_init);