Linux Audio

Check our new training course

Loading...
v5.9
 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	struct console *con;
 
13	size_t len = 0;
14
15	/* only dump kmsg when no console is available */
16	if (!console_trylock())
17		return;
18
19	for_each_console(con)
20		break;
 
 
 
 
21
22	console_unlock();
23
24	if (con)
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
34static struct kmsg_dumper kmsg_dumper = {
35	.dump = kmsg_dumper_stdout
36};
37
38int __init kmsg_dumper_stdout_init(void)
39{
40	return kmsg_dump_register(&kmsg_dumper);
41}
42
43__uml_postsetup(kmsg_dumper_stdout_init);
v5.14.15
 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);