Open stdin, stdout and stderr in the kernel rather than init.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-01-18 19:23:51 +01:00
parent 640465320f
commit b7bf21bfff
2 changed files with 16 additions and 9 deletions

View File

@ -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<Descriptor> root = CurrentProcess()->GetRoot();
Ref<DescriptorTable> dtable = process->GetDTable();
Ref<Descriptor> 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<Descriptor> 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<Descriptor> 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<Descriptor> init = root->open(&ctx, initpath, O_EXEC | O_READ);
if ( !init )
PanicF("Could not open %s in early kernel RAM filesystem:\n%s",

View File

@ -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);