LCOV - code coverage report
Current view: top level - arch/um/kernel - kmsg_dump.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 18 11.1 %
Date: 2022-12-09 01:23:36 Functions: 1 2 50.0 %

          Line data    Source code
       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             : 
      10           0 : static 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           0 :         size_t len = 0;
      19             : 
      20             :         /* only dump kmsg when no console is available */
      21           0 :         if (!console_trylock())
      22           0 :                 return;
      23             : 
      24           0 :         for_each_console(con) {
      25           0 :                 if(strcmp(con->name, "tty") == 0 &&
      26           0 :                    (con->flags & (CON_ENABLED | CON_CONSDEV)) != 0) {
      27             :                         break;
      28             :                 }
      29             :         }
      30             : 
      31           0 :         console_unlock();
      32             : 
      33           0 :         if (con)
      34             :                 return;
      35             : 
      36           0 :         if (!spin_trylock_irqsave(&lock, flags))
      37             :                 return;
      38             : 
      39           0 :         kmsg_dump_rewind(&iter);
      40             : 
      41           0 :         printf("kmsg_dump:\n");
      42           0 :         while (kmsg_dump_get_line(&iter, true, line, sizeof(line), &len)) {
      43           0 :                 line[len] = '\0';
      44           0 :                 printf("%s", line);
      45             :         }
      46             : 
      47           0 :         spin_unlock_irqrestore(&lock, flags);
      48             : }
      49             : 
      50             : static struct kmsg_dumper kmsg_dumper = {
      51             :         .dump = kmsg_dumper_stdout
      52             : };
      53             : 
      54           1 : int __init kmsg_dumper_stdout_init(void)
      55             : {
      56           1 :         return kmsg_dump_register(&kmsg_dumper);
      57             : }
      58             : 
      59             : __uml_postsetup(kmsg_dumper_stdout_init);

Generated by: LCOV version 1.14