From cda17ce4c14a10fbb0db13ce9dd98631bb3ae98a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 5 Jan 2017 15:02:54 -0700 Subject: [PATCH] Update init to handle directories --- filesystem/etc/init.d/00_base | 3 +++ filesystem/etc/init.d/10_net | 5 ++++ filesystem/etc/init.d/20_console | 2 ++ filesystem/etc/init.d/30_orbital | 1 + filesystem/etc/init.d/40_serial | 1 + filesystem/etc/init.rc | 12 ---------- initfs/etc/init.rc | 2 +- libc-artifacts | 2 +- programs/init/src/main.rs | 39 ++++++++++++++++++++++++++++---- 9 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 filesystem/etc/init.d/00_base create mode 100644 filesystem/etc/init.d/10_net create mode 100644 filesystem/etc/init.d/20_console create mode 100644 filesystem/etc/init.d/30_orbital create mode 100644 filesystem/etc/init.d/40_serial delete mode 100644 filesystem/etc/init.rc diff --git a/filesystem/etc/init.d/00_base b/filesystem/etc/init.d/00_base new file mode 100644 index 0000000..d34f472 --- /dev/null +++ b/filesystem/etc/init.d/00_base @@ -0,0 +1,3 @@ +/sbin/randd +/sbin/ptyd +/sbin/pcid /etc/pcid.toml diff --git a/filesystem/etc/init.d/10_net b/filesystem/etc/init.d/10_net new file mode 100644 index 0000000..21de468 --- /dev/null +++ b/filesystem/etc/init.d/10_net @@ -0,0 +1,5 @@ +/sbin/ethernetd +/sbin/ipd +/sbin/tcpd +/sbin/udpd +dhcpd -b diff --git a/filesystem/etc/init.d/20_console b/filesystem/etc/init.d/20_console new file mode 100644 index 0000000..ca6aeb0 --- /dev/null +++ b/filesystem/etc/init.d/20_console @@ -0,0 +1,2 @@ +getty display:2 +getty display:3 diff --git a/filesystem/etc/init.d/30_orbital b/filesystem/etc/init.d/30_orbital new file mode 100644 index 0000000..b1e505b --- /dev/null +++ b/filesystem/etc/init.d/30_orbital @@ -0,0 +1 @@ +/sbin/orbital display:4/activate /ui/bin/orblogin /ui/bin/launcher diff --git a/filesystem/etc/init.d/40_serial b/filesystem/etc/init.d/40_serial new file mode 100644 index 0000000..730fa10 --- /dev/null +++ b/filesystem/etc/init.d/40_serial @@ -0,0 +1 @@ +getty debug: -J diff --git a/filesystem/etc/init.rc b/filesystem/etc/init.rc deleted file mode 100644 index ca4b860..0000000 --- a/filesystem/etc/init.rc +++ /dev/null @@ -1,12 +0,0 @@ -/sbin/randd -/sbin/ptyd -/sbin/pcid /etc/pcid.toml -/sbin/ethernetd -/sbin/ipd -/sbin/tcpd -/sbin/udpd -dhcpd -b -getty display:2 -getty display:3 -/sbin/orbital display:4/activate /ui/bin/orblogin /ui/bin/launcher -getty debug: -J diff --git a/initfs/etc/init.rc b/initfs/etc/init.rc index 1bfc59d..97b35c2 100644 --- a/initfs/etc/init.rc +++ b/initfs/etc/init.rc @@ -6,4 +6,4 @@ pcid /etc/pcid.toml redoxfs disk:0 file cd file: export PATH file:/bin -run /etc/init.rc +run.d /etc/init.d diff --git a/libc-artifacts b/libc-artifacts index 67098b3..a3b7f7a 160000 --- a/libc-artifacts +++ b/libc-artifacts @@ -1 +1 @@ -Subproject commit 67098b38c671d7804c3b9b7b856090099d4cecda +Subproject commit a3b7f7af5e2695c309eb5d87158deb50cbbab2a6 diff --git a/programs/init/src/main.rs b/programs/init/src/main.rs index 1b010ce..56aa80e 100644 --- a/programs/init/src/main.rs +++ b/programs/init/src/main.rs @@ -1,11 +1,12 @@ extern crate syscall; use std::env; -use std::fs::File; +use std::fs::{File, read_dir}; use std::io::{BufRead, BufReader, Result}; +use std::path::Path; use std::process::Command; -pub fn run(file: &str) -> Result<()> { +pub fn run(file: &Path) -> Result<()> { let file = File::open(file)?; let reader = BufReader::new(file); @@ -46,12 +47,42 @@ pub fn run(file: &str) -> Result<()> { println!("init: failed to export: no argument"); }, "run" => if let Some(new_file) = args.next() { - if let Err(err) = run(&new_file) { + if let Err(err) = run(&Path::new(new_file)) { println!("init: failed to run '{}': {}", new_file, err); } } else { println!("init: failed to run: no argument"); }, + "run.d" => if let Some(new_dir) = args.next() { + match read_dir(new_dir) { + Ok(list) => { + let mut entries = vec![]; + for entry_res in list { + match entry_res { + Ok(entry) => { + entries.push(entry.path()); + }, + Err(err) => { + println!("init: failed to run.d: '{}': {}", new_dir, err); + } + } + } + + entries.sort(); + + for entry in entries { + if let Err(err) = run(&entry) { + println!("init: failed to run '{}': {}", entry.display(), err); + } + } + }, + Err(err) => { + println!("init: failed to run.d: '{}': {}", new_dir, err); + } + } + } else { + println!("init: failed to run.d: no argument"); + }, "stdio" => if let Some(stdio) = args.next() { let _ = syscall::close(2); let _ = syscall::close(1); @@ -86,7 +117,7 @@ pub fn run(file: &str) -> Result<()> { } pub fn main() { - if let Err(err) = run("initfs:etc/init.rc") { + if let Err(err) = run(&Path::new("initfs:etc/init.rc")) { println!("init: failed to run initfs:etc/init.rc: {}", err); }