Divide init into two files
This commit is contained in:
parent
77810d6713
commit
3eede6e7e7
11
filesystem/etc/init.rc
Normal file
11
filesystem/etc/init.rc
Normal file
|
@ -0,0 +1,11 @@
|
|||
initfs:bin/pcid /etc/pcid.toml
|
||||
vesad T T G
|
||||
ps2d
|
||||
ethernetd
|
||||
arpd
|
||||
ipd
|
||||
tcpd
|
||||
udpd
|
||||
getty display:1
|
||||
getty display:2
|
||||
orbital display:3
|
|
@ -1,13 +1,5 @@
|
|||
initfs:bin/pcid initfs:etc/pcid.toml
|
||||
initfs:bin/redoxfs disk:0
|
||||
initfs:bin/pcid file:etc/pcid.toml
|
||||
file:bin/vesad T T G
|
||||
file:bin/ps2d
|
||||
file:bin/ethernetd
|
||||
file:bin/arpd
|
||||
file:bin/ipd
|
||||
file:bin/tcpd
|
||||
file:bin/udpd
|
||||
file:bin/getty display:1
|
||||
file:bin/getty display:2
|
||||
#file:bin/orbital display:3
|
||||
cd file:
|
||||
export PATH file:bin
|
||||
run /etc/init.rc
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::io::{BufRead, BufReader, Result};
|
||||
use std::process::Command;
|
||||
|
||||
pub fn main() {
|
||||
let file = File::open("initfs:etc/init.rc").expect("failed to open init.rc");
|
||||
pub fn run(file: &str) -> Result<()> {
|
||||
let file = File::open(file)?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
for line_result in reader.lines() {
|
||||
let line = line_result.expect("failed to read init.rc");
|
||||
let line = line_result?;
|
||||
let line = line.trim();
|
||||
if ! line.is_empty() && ! line.starts_with('#') {
|
||||
let mut args = line.split(' ');
|
||||
if let Some(cmd) = args.next() {
|
||||
match cmd {
|
||||
"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");
|
||||
},
|
||||
"echo" => {
|
||||
if let Some(arg) = args.next() {
|
||||
print!("{}", arg);
|
||||
|
@ -23,12 +30,25 @@ pub fn main() {
|
|||
}
|
||||
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);
|
||||
"export" => if let Some(var) = args.next() {
|
||||
let mut value = String::new();
|
||||
if let Some(arg) = args.next() {
|
||||
value.push_str(&arg);
|
||||
}
|
||||
for arg in args {
|
||||
value.push(' ');
|
||||
value.push_str(&arg);
|
||||
}
|
||||
env::set_var(var, value);
|
||||
} else {
|
||||
println!("init: failed to export: no argument");
|
||||
},
|
||||
"run" => if let Some(new_file) = args.next() {
|
||||
if let Err(err) = run(&new_file) {
|
||||
println!("init: failed to run '{}': {}", new_file, err);
|
||||
}
|
||||
} else {
|
||||
println!("init: failed to cd: no argument");
|
||||
println!("init: failed to run: no argument");
|
||||
},
|
||||
_ => {
|
||||
let mut command = Command::new(cmd);
|
||||
|
@ -48,4 +68,12 @@ pub fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
if let Err(err) = run("initfs:etc/init.rc") {
|
||||
println!("init: failed to run initfs:etc/init.rc: {}", err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7e7d2ada724c48b01a69ba72b105392557fa634c
|
||||
Subproject commit 2212c9b4822c44af90164bffeef29d903e6b39da
|
|
@ -1 +1 @@
|
|||
Subproject commit b556eefe6071700905abef862967a316dc5b65c7
|
||||
Subproject commit 3b7448c8fdb15857b813a90b2fba81393ef043be
|
|
@ -1 +1 @@
|
|||
Subproject commit c21bd7618907c5d146c947e9b38d64fdb7479528
|
||||
Subproject commit b2fa6a54d58691be8b6d30235a6668db3d29124a
|
Loading…
Reference in a new issue