init: Open /dev/console from rootfs

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Thursday, March 4, 2010 - 10:01 am

Gitweb:     http://git.kernel.org/linus/2bd3a997befc226ab4b504f05c5cbba305f3e0e6
Commit:     2bd3a997befc226ab4b504f05c5cbba305f3e0e6
Parent:     2329e392accdb1b277927e8d9cbf568ba3f3856d
Author:     Eric W. Biederman <ebiederm@xmission.com>
AuthorDate: Tue Mar 2 23:53:19 2010 -0800
Committer:  Al Viro <viro@zeniv.linux.org.uk>
CommitDate: Wed Mar 3 14:56:07 2010 -0500

    init: Open /dev/console from rootfs
    
    To avoid potential problems with an empty /dev open /dev/console
    from rootfs instead of waiting to mount our root filesystem and
    mounting it there.   This effectively guarantees that there will
    be a device node, and it won't be on a filesystem that we will
    ever unmount, so there are no issues with leaving /dev/console
    open and pinning the filesystem.
    
    This is actually more effective than automatically mounting
    devtmpfs on /dev because it removes removes the occasionally
    problematic assumption that /dev/console exists from the boot
    code.
    
    With this patch I was able to throw busybox on my /boot partition
    (which has no /dev directory) and boot into userspace without
    problems.
    
    The only possible negative consequence I can think of is that
    someone out there deliberately used did not use a character device
    that is major 5 minor 2 for /dev/console.  Does anyone know of a
    situation in which that could make sense?
    
    Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 init/do_mounts_initrd.c |    4 ----
 init/main.c             |   11 ++++++-----
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 614241b..2b10853 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -30,11 +30,7 @@ static int __init do_linuxrc(void * shell)
 	extern char * envp_init[];
 
 	sys_close(old_fd);sys_close(root_fd);
-	sys_close(0);sys_close(1);sys_close(2);
 	sys_setsid();
-	(void) sys_open("/dev/console",O_RDWR,0);
-	(void) sys_dup(0);
-	(void) sys_dup(0);
 	return kernel_execve(shell, argv, envp_init);
 }
 
diff --git a/init/main.c b/init/main.c
index 4cb47a1..106e02d 100644
--- a/init/main.c
+++ b/init/main.c
@@ -806,11 +806,6 @@ static noinline int init_post(void)
 	system_state = SYSTEM_RUNNING;
 	numa_default_policy();
 
-	if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
-		printk(KERN_WARNING "Warning: unable to open an initial console.\n");
-
-	(void) sys_dup(0);
-	(void) sys_dup(0);
 
 	current->signal->flags |= SIGNAL_UNKILLABLE;
 
@@ -873,6 +868,12 @@ static int __init kernel_init(void * unused)
 
 	do_basic_setup();
 
+	/* Open the /dev/console on the rootfs, this should never fail */
+	if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
+		printk(KERN_WARNING "Warning: unable to open an initial console.\n");
+
+	(void) sys_dup(0);
+	(void) sys_dup(0);
 	/*
 	 * check if there is an early userspace init.  If yes, let it do all
 	 * the work
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
init: Open /dev/console from rootfs, Linux Kernel Mailing ..., (Thu Mar 4, 10:01 am)