Index: sys/kern/init_main.c =================================================================== --- sys/kern/init_main.c +++ sys/kern/init_main.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -669,6 +670,40 @@ CTLFLAG_RW, &init_shutdown_timeout, 0, "Shutdown timeout of init(8). " "Unused within kernel, but used to control init(8)"); +static void +open_initial_fds(void) +{ + struct thread *td; + int devconsole, error; + + td = curthread; + + error = kern_openat(td, AT_FDCWD, "/dev/console", + UIO_SYSSPACE, O_RDWR | O_NONBLOCK, 0); + if (error != 0) { + if (bootverbose || error != EWOULDBLOCK) + printf("%s: cannot open /dev/console, error = %d\n", + __func__, error); + return; + } + devconsole = td->td_retval[0]; + KASSERT(devconsole == 0, ("we didn't get our fd")); + + error = kern_dup(td, FDDUP_FIXED, 0, devconsole, 1); + if (error != 0) { + printf("%s: kern_dup() failed for stdout with error %d\n", + __func__, error); + return; + } + + error = kern_dup(td, FDDUP_FIXED, 0, devconsole, 2); + if (error != 0) { + printf("%s: kern_dup() failed for stderr with error %d\n", + __func__, error); + return; + } +} + /* * Start the initial user process; try exec'ing each pathname in init_path. * The program is invoked with one argument containing the boot flags. @@ -711,6 +746,8 @@ freeenv(var); } + open_initial_fds(); + for (path = init_path; *path != '\0'; path = next) { while (*path == ':') path++;