Skip to content

Commit 8f74063

Browse files
author
Christoph Hellwig
committed
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: Christoph Hellwig <[email protected]> Acked-by: Linus Torvalds <[email protected]>
1 parent bf6419e commit 8f74063

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

init/main.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,15 +1457,19 @@ static int __ref kernel_init(void *unused)
14571457
"See Linux Documentation/admin-guide/init.rst for guidance.");
14581458
}
14591459

1460+
/* Open /dev/console, for stdin/stdout/stderr, this should never fail */
14601461
void console_on_rootfs(void)
14611462
{
1462-
/* Open the /dev/console as stdin, this should never fail */
1463-
if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1464-
pr_err("Warning: unable to open an initial console.\n");
1463+
struct file *file = filp_open("/dev/console", O_RDWR, 0);
14651464

1466-
/* create stdout/stderr */
1467-
(void) ksys_dup(0);
1468-
(void) ksys_dup(0);
1465+
if (IS_ERR(file)) {
1466+
pr_err("Warning: unable to open an initial console.\n");
1467+
return;
1468+
}
1469+
get_file_rcu_many(file, 2);
1470+
fd_install(get_unused_fd_flags(0), file);
1471+
fd_install(get_unused_fd_flags(0), file);
1472+
fd_install(get_unused_fd_flags(0), file);
14691473
}
14701474

14711475
static noinline void __init kernel_init_freeable(void)

0 commit comments

Comments
 (0)