From b7bf21bffffcea5692b261a6bdaba071dce8fb73 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 18 Jan 2014 19:23:51 +0100 Subject: [PATCH] Open stdin, stdout and stderr in the kernel rather than init. --- kernel/kernel.cpp | 18 ++++++++++++++++-- utils/init.cpp | 7 ------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 6b38e3cc..901fc039 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -709,10 +709,24 @@ static void InitThread(void* /*user*/) Process* process = CurrentProcess(); - const char* initpath = "/" CPUTYPE_STR "/bin/init"; - ioctx_t ctx; SetupKernelIOCtx(&ctx); Ref root = CurrentProcess()->GetRoot(); + + Ref dtable = process->GetDTable(); + + Ref tty_stdin = root->open(&ctx, "/dev/tty", O_READ); + if ( !tty_stdin || dtable->Allocate(tty_stdin, 0) != 0 ) + Panic("Could not prepare stdin for initialization process"); + Ref tty_stdout = root->open(&ctx, "/dev/tty", O_WRITE); + if ( !tty_stdout || dtable->Allocate(tty_stdout, 0) != 1 ) + Panic("Could not prepare stdout for initialization process"); + Ref tty_stderr = root->open(&ctx, "/dev/tty", O_WRITE); + if ( !tty_stderr || dtable->Allocate(tty_stderr, 0) != 2 ) + Panic("Could not prepare stderr for initialization process"); + + dtable.Reset(); + + const char* initpath = "/" CPUTYPE_STR "/bin/init"; Ref init = root->open(&ctx, initpath, O_EXEC | O_READ); if ( !init ) PanicF("Could not open %s in early kernel RAM filesystem:\n%s", diff --git a/utils/init.cpp b/utils/init.cpp index c0dc5847..7d59d2ae 100644 --- a/utils/init.cpp +++ b/utils/init.cpp @@ -471,13 +471,6 @@ retry_ask_root_block_device: int main(int /*argc*/, char* /*argv*/[]) { - if ( !has_descriptor(0) && open("/dev/tty", O_RDONLY) != 0 ) - return 2; - if ( !has_descriptor(1) && open("/dev/tty", O_WRONLY | O_APPEND) != 1 ) - return 2; - if ( !has_descriptor(2) && open("/dev/tty", O_WRONLY | O_APPEND) != 2 ) - return 2; - // Reset the terminal's color and the rest of it. printf(BRAND_INIT_BOOT_MESSAGE); fflush(stdout);