Skip to content

Commit b49a733

Browse files
author
Dominik Brodowski
committed
init: unify opening /dev/console as stdin/stdout/stderr
Merge the two instances where /dev/console is opened as stdin/stdout/stderr. Signed-off-by: Dominik Brodowski <[email protected]>
1 parent cccaa5e commit b49a733

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

include/linux/initrd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ extern unsigned int real_root_dev;
2828

2929
extern char __initramfs_start[];
3030
extern unsigned long __initramfs_size;
31+
32+
void console_on_rootfs(void);

init/do_mounts_initrd.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ early_param("initrd", early_initrd);
4848
static int init_linuxrc(struct subprocess_info *info, struct cred *new)
4949
{
5050
ksys_unshare(CLONE_FS | CLONE_FILES);
51-
/* stdin/stdout/stderr for /linuxrc */
52-
ksys_open("/dev/console", O_RDWR, 0);
53-
ksys_dup(0);
54-
ksys_dup(0);
51+
console_on_rootfs();
5552
/* move initrd over / and chdir/chroot in initrd root */
5653
ksys_chdir("/root");
5754
do_mount(".", "/", NULL, MS_MOVE, NULL);

init/main.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,17 @@ static int __ref kernel_init(void *unused)
11551155
"See Linux Documentation/admin-guide/init.rst for guidance.");
11561156
}
11571157

1158+
void console_on_rootfs(void)
1159+
{
1160+
/* Open the /dev/console as stdin, this should never fail */
1161+
if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1162+
pr_err("Warning: unable to open an initial console.\n");
1163+
1164+
/* create stdout/stderr */
1165+
(void) ksys_dup(0);
1166+
(void) ksys_dup(0);
1167+
}
1168+
11581169
static noinline void __init kernel_init_freeable(void)
11591170
{
11601171
/*
@@ -1190,12 +1201,8 @@ static noinline void __init kernel_init_freeable(void)
11901201

11911202
do_basic_setup();
11921203

1193-
/* Open the /dev/console on the rootfs, this should never fail */
1194-
if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1195-
pr_err("Warning: unable to open an initial console.\n");
1204+
console_on_rootfs();
11961205

1197-
(void) ksys_dup(0);
1198-
(void) ksys_dup(0);
11991206
/*
12001207
* check if there is an early userspace init. If yes, let it do all
12011208
* the work

0 commit comments

Comments
 (0)