aboutsummaryrefslogtreecommitdiffstats
path: root/patches/boot/check-console-device-file-on-fs-when-booting.patch
blob: d1f3a3390afb5b0cab980462f4cd3e74b0319175 (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 2f9c3e4ee446d66e110973eb5bf9f4f00220f186 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.

vfs_lstat() which was used previously would fail with certain
configurations. This was likely due to the involved functions being
marked __init at some point in the past.

Signed-off-by: Richard Laroque <rlarocqu@windriver.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
---
 init/main.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index 649d9e4201a8..4e6af76ca199 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1574,7 +1574,21 @@ static int __ref kernel_init(void *unused)
 /* Open /dev/console, for stdin/stdout/stderr, this should never fail */
 void __init console_on_rootfs(void)
 {
-	struct file *file = filp_open("/dev/console", O_RDWR, 0);
+	struct file *file;
+
+#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
+	 */
+	struct kstat stat;
+	if (init_stat("/dev/console", &stat, 0) || !S_ISCHR(stat.mode)) {
+		panic("/dev/console is missing or not a character device!\nPlease ensure your rootfs is properly configured\n");
+	}
+#endif
+
+	file = filp_open("/dev/console", O_RDWR, 0);
 
 	if (IS_ERR(file)) {
 		pr_err("Warning: unable to open an initial console.\n");
-- 
2.19.1