Commit 8f740636 authored by Christoph Hellwig's avatar Christoph Hellwig

init: open code setting up stdin/stdout/stderr

Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to work, but
instead open a struct file for /dev/console and then install it as FD
0/1/2 manually.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bf6419e4
...@@ -1457,15 +1457,19 @@ static int __ref kernel_init(void *unused) ...@@ -1457,15 +1457,19 @@ static int __ref kernel_init(void *unused)
"See Linux Documentation/admin-guide/init.rst for guidance."); "See Linux Documentation/admin-guide/init.rst for guidance.");
} }
/* Open /dev/console, for stdin/stdout/stderr, this should never fail */
void console_on_rootfs(void) void console_on_rootfs(void)
{ {
/* Open the /dev/console as stdin, this should never fail */ struct file *file = filp_open("/dev/console", O_RDWR, 0);
if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
pr_err("Warning: unable to open an initial console.\n");
/* create stdout/stderr */ if (IS_ERR(file)) {
(void) ksys_dup(0); pr_err("Warning: unable to open an initial console.\n");
(void) ksys_dup(0); return;
}
get_file_rcu_many(file, 2);
fd_install(get_unused_fd_flags(0), file);
fd_install(get_unused_fd_flags(0), file);
fd_install(get_unused_fd_flags(0), file);
} }
static noinline void __init kernel_init_freeable(void) static noinline void __init kernel_init_freeable(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment