Merge the two instances where /dev/console is opened as stdin/stdout/stderr.
Unified · Split
| @@ -28,3 +28,5 @@ extern unsigned int real_root_dev; · 27 unmodified lines | ||
| 28 | 28 | |
| 29 | 29 | extern char __initramfs_start[]; |
| 30 | 30 | extern unsigned long __initramfs_size; |
| 31 | + | |
| 32 | +void console_on_rootfs(void); | |
| @@ -48,10 +48,7 @@ early_param("initrd", early_initrd); · 47 unmodified lines | ||
| 48 | 48 | static int init_linuxrc(struct subprocess_info *info, struct cred *new) |
| 49 | 49 | { |
| 50 | 50 | 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(); | |
| 55 | 52 | /* move initrd over / and chdir/chroot in initrd root */ |
| 56 | 53 | ksys_chdir("/root"); |
| 57 | 54 | do_mount(".", "/", NULL, MS_MOVE, NULL); |
| @@ -1155,6 +1155,17 @@ static int __ref kernel_init(void *unused) · 1154 unmodified lines | ||
| 1155 | 1155 | "See Linux Documentation/admin-guide/init.rst for guidance."); |
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 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 | + | |
| 1158 | 1169 | static 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 | 1202 | do_basic_setup(); |
| 1192 | 1203 | |
| 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(); | |
| 1196 | 1205 | |
| 1197 | − (void) ksys_dup(0); | |
| 1198 | − (void) ksys_dup(0); | |
| 1199 | 1206 | /* |
| 1200 | 1207 | * check if there is an early userspace init. If yes, let it do all |
| 1201 | 1208 | * the work |