From c81388d92940c4820cbbcf351f638f318668a6f4 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 17 Oct 2016 11:00:55 -0600 Subject: [PATCH] Allow init to change stdio --- programs/init/Cargo.toml | 3 +++ programs/init/src/main.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/programs/init/Cargo.toml b/programs/init/Cargo.toml index cd1a1ed..dd47c74 100644 --- a/programs/init/Cargo.toml +++ b/programs/init/Cargo.toml @@ -1,3 +1,6 @@ [package] name = "init" version = "0.1.0" + +[dependencies] +syscall = { path = "../../syscall" } diff --git a/programs/init/src/main.rs b/programs/init/src/main.rs index 09c64f6..f6e6a98 100644 --- a/programs/init/src/main.rs +++ b/programs/init/src/main.rs @@ -1,3 +1,5 @@ +extern crate syscall; + use std::env; use std::fs::File; use std::io::{BufRead, BufReader, Result}; @@ -50,6 +52,17 @@ pub fn run(file: &str) -> Result<()> { } else { println!("init: failed to run: no argument"); }, + "stdio" => if let Some(stdio) = args.next() { + let _ = syscall::close(2); + let _ = syscall::close(1); + let _ = syscall::close(0); + + let _ = syscall::open(&stdio, syscall::flag::O_RDWR); + let _ = syscall::open(&stdio, syscall::flag::O_RDWR); + let _ = syscall::open(&stdio, syscall::flag::O_RDWR); + } else { + println!("init: failed to set stdio: no argument"); + }, _ => { let mut command = Command::new(cmd); for arg in args {