Commit 6ab16af3 authored by Jeremy Soller's avatar Jeremy Soller

Add login process. Remove debugging. Fix order of arguments

parents
[package]
name = "init"
version = "0.1.0"
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::process::Command;
pub fn main() {
let file = File::open("initfs:etc/init.rc").expect("failed to open init.rc");
let reader = BufReader::new(file);
for line_result in reader.lines() {
let line = line_result.expect("failed to read init.rc");
let line = line.trim();
if ! line.is_empty() && ! line.starts_with('#') {
let mut args = line.split(' ');
if let Some(cmd) = args.next() {
match cmd {
"echo" => {
if let Some(arg) = args.next() {
print!("{}", arg);
}
for arg in args {
print!(" {}", arg);
}
print!("\n");
},
"cd" => if let Some(dir) = args.next() {
if let Err(err) = env::set_current_dir(dir) {
println!("init: failed to cd to '{}': {}", dir, err);
}
} else {
println!("init: failed to cd: no argument");
},
_ => {
let mut command = Command::new(cmd);
for arg in args {
command.arg(arg);
}
match command.spawn() {
Ok(mut child) => match child.wait() {
Ok(_status) => (), //println!("init: waited for {}: {:?}", line, status.code()),
Err(err) => println!("init: failed to wait for '{}': {}", line, err)
},
Err(err) => println!("init: failed to execute '{}': {}", line, err)
}
}
}
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment