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
28 28
29extern char __initramfs_start[];29extern char __initramfs_start[];
30extern unsigned long __initramfs_size;30extern unsigned long __initramfs_size;
31
32void console_on_rootfs(void);
init/do_mounts_initrd.c+1−4
@@ -48,10 +48,7 @@ early_param("initrd", early_initrd); · 47 unmodified lines
48static int init_linuxrc(struct subprocess_info *info, struct cred *new)48static int init_linuxrc(struct subprocess_info *info, struct cred *new)
49{49{
50 ksys_unshare(CLONE_FS | CLONE_FILES);50 ksys_unshare(CLONE_FS | CLONE_FILES);
51 /* stdin/stdout/stderr for /linuxrc */51 console_on_rootfs();
52 ksys_open("/dev/console", O_RDWR, 0);
53 ksys_dup(0);
54 ksys_dup(0);
55 /* move initrd over / and chdir/chroot in initrd root */52 /* move initrd over / and chdir/chroot in initrd root */
56 ksys_chdir("/root");53 ksys_chdir("/root");
57 do_mount(".", "/", NULL, MS_MOVE, NULL);54 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
1155 "See Linux Documentation/admin-guide/init.rst for guidance.");1155 "See Linux Documentation/admin-guide/init.rst for guidance.");
1156}1156}
1157 1157
1158void 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
1158static noinline void __init kernel_init_freeable(void)1169static noinline void __init kernel_init_freeable(void)
1159{1170{
1160 /*1171 /*
@@ -1190,12 +1201,8 @@ static noinline void __init kernel_init_freeable(void) · 29 unmodified lines
1190 1201
1191 do_basic_setup();1202 do_basic_setup();
1192 1203
1193 /* Open the /dev/console on the rootfs, this should never fail */1204 console_on_rootfs();
1194 if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1195 pr_err("Warning: unable to open an initial console.\n");
1196 1205
1197 (void) ksys_dup(0);
1198 (void) ksys_dup(0);
1199 /*1206 /*
1200 * check if there is an early userspace init. If yes, let it do all1207 * check if there is an early userspace init. If yes, let it do all
1201 * the work1208 * 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