History

init: unify opening /dev/console as stdin/stdout/stderr

Merge the two instances where /dev/console is opened as stdin/stdout/stderr.

Dominik Brodowski committed 8 years ago

Commit b49a7331 parent cccaa5e3 files · +15 −9Browse files

Unified · Split

3 files
  1. include/linux/initrd.h +2 −0
  2. init/do_mounts_initrd.c +1 −4
  3. init/main.c +12 −5
include/linux/initrd.h+2−0
@@ -28,3 +28,5 @@ extern unsigned int real_root_dev; · 27 unmodified lines
2828
2929 extern char __initramfs_start[];
3030 extern unsigned long __initramfs_size;
31+
32+void console_on_rootfs(void);
init/do_mounts_initrd.c+1−4
@@ -48,10 +48,7 @@ early_param("initrd", early_initrd); · 47 unmodified lines
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+12−5
@@ -1155,6 +1155,17 @@ static int __ref kernel_init(void *unused) · 1154 unmodified lines
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) · 29 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t