]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - init/main.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[mirror_ubuntu-jammy-kernel.git] / init / main.c
index 91f6ebb30ef041a8667c18b949ccf42e976174e1..1ecfd43ed4643461af60bb47f5d4f61aad9b12af 100644 (file)
@@ -93,6 +93,7 @@
 #include <linux/rodata_test.h>
 #include <linux/jump_label.h>
 #include <linux/mem_encrypt.h>
+#include <linux/file.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -1155,6 +1156,30 @@ static int __ref kernel_init(void *unused)
              "See Linux Documentation/admin-guide/init.rst for guidance.");
 }
 
+void console_on_rootfs(void)
+{
+       struct file *file;
+       unsigned int i;
+
+       /* Open /dev/console in kernelspace, this should never fail */
+       file = filp_open("/dev/console", O_RDWR, 0);
+       if (IS_ERR(file))
+               goto err_out;
+
+       /* create stdin/stdout/stderr, this should never fail */
+       for (i = 0; i < 3; i++) {
+               if (f_dupfd(i, file, 0) != i)
+                       goto err_out;
+       }
+
+       return;
+
+err_out:
+       /* no panic -- this might not be fatal */
+       pr_err("Warning: unable to open an initial console.\n");
+       return;
+}
+
 static noinline void __init kernel_init_freeable(void)
 {
        /*
@@ -1190,12 +1215,8 @@ static noinline void __init kernel_init_freeable(void)
 
        do_basic_setup();
 
-       /* Open the /dev/console on the rootfs, this should never fail */
-       if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
-               pr_err("Warning: unable to open an initial console.\n");
+       console_on_rootfs();
 
-       (void) ksys_dup(0);
-       (void) ksys_dup(0);
        /*
         * check if there is an early userspace init.  If yes, let it do all
         * the work