aboutsummaryrefslogtreecommitdiffstats
path: root/patches/boot/check-console-device-file-on-fs-when-booting.patch
blob: bbe2665958e992acde3f0f8dc4dea0cbfb8f1a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
From 4a8d1cb76c2a95efbc75659a43ac643f22e8a155 Mon Sep 17 00:00:00 2001
From: Bruce Ashfield <bruce.ashfield@windriver.com>
Date: Thu, 8 Apr 2010 23:44:21 -0700
Subject: [PATCH] check console device file on fs when booting

If a root filesystem is generated as non-root, one of
the tell tale signs is /dev/console not being a character
file. To save a whole class of questions, let's just test
for the condition and let the user know.

Signed-off-by: Richard Laroque <rlarocqu@windriver.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
---
 init/main.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/init/main.c b/init/main.c
index ae78fb68d231..69bc15d35dd0 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1463,6 +1463,18 @@ static int __ref kernel_init(void *unused)
 /* Open /dev/console, for stdin/stdout/stderr, this should never fail */
 void __init console_on_rootfs(void)
 {
+#ifndef CONFIG_BLK_DEV_INITRD
+       /*
+        * Use /dev/console to infer if the rootfs is setup properly.
+        * In case of initrd or initramfs /dev/console might be instantiated
+        * later by /init so don't do this check for CONFIG_BLK_DEV_INITRD
+        */
+	if (vfs_lstat((char __user *) "/dev/console", (struct kstat __user *) &console_stat)
+			|| !S_ISCHR(console_stat.mode)) {
+		panic("/dev/console is missing or not a character device!\nPlease ensure your rootfs is properly configured\n");
+	}
+#endif
+
 	struct file *file = filp_open("/dev/console", O_RDWR, 0);
 
 	if (IS_ERR(file)) {
@@ -1477,6 +1489,9 @@ void __init console_on_rootfs(void)
 
 static noinline void __init kernel_init_freeable(void)
 {
+#ifndef CONFIG_BLK_DEV_INITRD
+	struct kstat console_stat;
+#endif
 	/*
 	 * Wait until kthreadd is all set-up.
 	 */
-- 
2.19.1