From 6ab16af3f5563c7bc38f92aa9769e57f6218f4fa Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 22 Sep 2016 08:43:22 -0600 Subject: [PATCH 01/43] Add login process. Remove debugging. Fix order of arguments --- Cargo.toml | 3 +++ src/main.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..cd1a1ed8f9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "init" +version = "0.1.0" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000000..bae77fa22f --- /dev/null +++ b/src/main.rs @@ -0,0 +1,51 @@ +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) + } + } + } + } + } + } +} From 385df792b088d085aedaa10379042a5d3d21d183 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 14 Oct 2016 21:11:29 -0600 Subject: [PATCH 02/43] Divide init into two files --- src/main.rs | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index bae77fa22f..09c64f66e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); + } } From 665eaa529859bda3fe6e040d99e6961a6bf0de18 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 17 Oct 2016 11:00:55 -0600 Subject: [PATCH 03/43] Allow init to change stdio --- Cargo.toml | 3 +++ src/main.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index cd1a1ed8f9..dd47c74345 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ [package] name = "init" version = "0.1.0" + +[dependencies] +syscall = { path = "../../syscall" } diff --git a/src/main.rs b/src/main.rs index 09c64f66e9..f6e6a98f00 100644 --- a/src/main.rs +++ b/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 { From cde0a9c8a1dbd1926655c67b909de05e921cc1cd Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 1 Nov 2016 11:04:53 -0600 Subject: [PATCH 04/43] Correct init process, allow waiting on any children, reap zombies in init --- src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.rs b/src/main.rs index f6e6a98f00..1b010ce63d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,4 +89,9 @@ pub fn main() { if let Err(err) = run("initfs:etc/init.rc") { println!("init: failed to run initfs:etc/init.rc: {}", err); } + + loop { + let mut status = 0; + syscall::waitpid(0, &mut status, 0).unwrap(); + } } From 83c58e0486576cd6bbc1b7f7cd9d37f738162bc1 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 2 Nov 2016 19:48:25 -0600 Subject: [PATCH 05/43] Remove resource_sceme, Fix syscall crate name, add fmap --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dd47c74345..b045ad65e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ name = "init" version = "0.1.0" [dependencies] -syscall = { path = "../../syscall" } +redox_syscall = { path = "../../syscall" } From 552ce2c4b4b7954b26c3014c5180ceb47289f63b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 5 Jan 2017 15:02:54 -0700 Subject: [PATCH 06/43] Update init to handle directories --- src/main.rs | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1b010ce63d..56aa80e12f 100644 --- a/src/main.rs +++ b/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); } From c95f2dec04b542ce44b52c1760d042542c260d52 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 9 Jan 2017 20:38:42 -0700 Subject: [PATCH 07/43] Update submodules --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b045ad65e4..0ababa4c6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ name = "init" version = "0.1.0" [dependencies] -redox_syscall = { path = "../../syscall" } +redox_syscall = { git = "https://github.com/redox-os/syscall.git" } From 61ff636174b49bc5a29413ccb8f0f02ab35903d8 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 12 Jan 2017 18:41:11 -0700 Subject: [PATCH 08/43] Fix issue with init script stdio failing on vga=no --- src/main.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 56aa80e12f..9c4c4d422f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,26 @@ +#![deny(warnings)] + extern crate syscall; use std::env; -use std::fs::{File, read_dir}; -use std::io::{BufRead, BufReader, Result}; +use std::fs::{File, OpenOptions, read_dir}; +use std::io::{BufRead, BufReader, Error, Result}; +use std::os::unix::io::AsRawFd; use std::path::Path; use std::process::Command; +fn switch_stdio(stdio: &str) -> Result<()> { + let stdin = OpenOptions::new().read(true).open(stdio)?; + let stdout = OpenOptions::new().write(true).open(stdio)?; + let stderr = OpenOptions::new().write(true).open(stdio)?; + + syscall::dup2(stdin.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + syscall::dup2(stdout.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + syscall::dup2(stderr.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + + Ok(()) +} + pub fn run(file: &Path) -> Result<()> { let file = File::open(file)?; let reader = BufReader::new(file); @@ -84,13 +99,9 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to run.d: 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); + if let Err(err) = switch_stdio(&stdio) { + println!("init: failed to switch stdio to '{}': {}", stdio, err); + } } else { println!("init: failed to set stdio: no argument"); }, From c8a4a0d67ca601e3b43bf1555303eb521f9689f5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 12 Jan 2017 19:13:38 -0700 Subject: [PATCH 09/43] Mistake in init using wrong fd in dup2, update userutils --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9c4c4d422f..d4c3ebd04d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,8 +15,8 @@ fn switch_stdio(stdio: &str) -> Result<()> { let stderr = OpenOptions::new().write(true).open(stdio)?; syscall::dup2(stdin.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; - syscall::dup2(stdout.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; - syscall::dup2(stderr.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + syscall::dup2(stdout.as_raw_fd(), 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + syscall::dup2(stderr.as_raw_fd(), 2, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; Ok(()) } From 1b684e24064c911705112ecc9a92a7f5e17c0418 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 13 Jan 2017 15:10:43 -0700 Subject: [PATCH 10/43] Specify crates.io versions, update rust, cleanup modules --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0ababa4c6f..955abf76ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ name = "init" version = "0.1.0" [dependencies] -redox_syscall = { git = "https://github.com/redox-os/syscall.git" } +redox_syscall = "0.1" From 6c1f476735e11d84b445dc8e60662f94f96434cc Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 15 Apr 2017 09:56:59 -0600 Subject: [PATCH 11/43] Prevent files from being passed by init to launched children --- src/main.rs | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index d4c3ebd04d..bc388d5b7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ extern crate syscall; use std::env; use std::fs::{File, OpenOptions, read_dir}; -use std::io::{BufRead, BufReader, Error, Result}; +use std::io::{Read, Error, Result}; use std::os::unix::io::AsRawFd; use std::path::Path; use std::process::Command; @@ -22,11 +22,10 @@ fn switch_stdio(stdio: &str) -> Result<()> { } pub fn run(file: &Path) -> Result<()> { - let file = File::open(file)?; - let reader = BufReader::new(file); + let mut data = String::new(); + File::open(file)?.read_to_string(&mut data)?; - for line_result in reader.lines() { - let line = line_result?; + for line in data.lines() { let line = line.trim(); if ! line.is_empty() && ! line.starts_with('#') { let mut args = line.split(' '); @@ -69,25 +68,15 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to run: no argument"); }, "run.d" => if let Some(new_dir) = args.next() { + let mut entries = vec![]; 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); + Ok(list) => 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); } } }, @@ -95,6 +84,14 @@ pub fn run(file: &Path) -> Result<()> { 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); + } + } } else { println!("init: failed to run.d: no argument"); }, From 032a45c55242aebaa9f6a03fa9d11da881bfcb1f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 16 Apr 2017 12:50:26 -0600 Subject: [PATCH 12/43] Open stdio without cloexec --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index bc388d5b7e..786689f23a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,16 +3,23 @@ extern crate syscall; use std::env; -use std::fs::{File, OpenOptions, read_dir}; +use std::fs::{File, read_dir}; use std::io::{Read, Error, Result}; -use std::os::unix::io::AsRawFd; +use std::os::unix::io::{AsRawFd, FromRawFd}; use std::path::Path; use std::process::Command; +use syscall::flag::{O_RDONLY, O_WRONLY}; fn switch_stdio(stdio: &str) -> Result<()> { - let stdin = OpenOptions::new().read(true).open(stdio)?; - let stdout = OpenOptions::new().write(true).open(stdio)?; - let stderr = OpenOptions::new().write(true).open(stdio)?; + let stdin = unsafe { File::from_raw_fd( + syscall::open(stdio, O_RDONLY).map_err(|err| Error::from_raw_os_error(err.errno))? + ) }; + let stdout = unsafe { File::from_raw_fd( + syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? + ) }; + let stderr = unsafe { File::from_raw_fd( + syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? + ) }; syscall::dup2(stdin.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; syscall::dup2(stdout.as_raw_fd(), 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; From abd68c2ef30e7fa3812ea26da7e50dbefe48ce18 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 22 Jul 2017 13:51:21 -0600 Subject: [PATCH 13/43] Add gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..fa8d85ac52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Cargo.lock +target From 8c9a42a8098f24b2bea681c784035a6a2feebf28 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 26 Jul 2017 07:54:19 -0600 Subject: [PATCH 14/43] Add Cargo.lock --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fa8d85ac52..b83d22266a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -Cargo.lock -target +/target/ From 31830fb9afa66f98752136ccddc27c00a6b7c5e2 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 26 Jul 2017 08:02:31 -0600 Subject: [PATCH 15/43] Add Cargo.lock file --- Cargo.lock | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..635f58bf13 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,14 @@ +[root] +name = "init" +version = "0.1.0" +dependencies = [ + "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_syscall" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "80dcf663dc552529b9bfc7bdb30ea12e5fa5d3545137d850a91ad410053f68e9" From 7c27222bb82bc765801b254e3f73dba7fc4c56da Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 29 Jul 2017 08:24:39 -0600 Subject: [PATCH 16/43] Update Cargo.lock --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 635f58bf13..25317c88e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "80dcf663dc552529b9bfc7bdb30ea12e5fa5d3545137d850a91ad410053f68e9" +"checksum redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "ddab7acd8e7bf3e49dfdf78ac1209b992329eb2f66e0bf672ab49c70a76d1d68" From 529c9f69eb2d5387469387f6354869a2fb2316e5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 2 Aug 2017 19:53:06 -0600 Subject: [PATCH 17/43] Update Cargo.lock --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25317c88e4..55bcb1151e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "ddab7acd8e7bf3e49dfdf78ac1209b992329eb2f66e0bf672ab49c70a76d1d68" +"checksum redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9309631a35303bffb47e397198e3668cb544fe8834cd3da2a744441e70e524" From 5f11f72489c0b3f24c753ad13627c860941b9140 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 19 Aug 2017 14:47:00 -0600 Subject: [PATCH 18/43] Update Cargo.lock --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55bcb1151e..7f18a23034 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9309631a35303bffb47e397198e3668cb544fe8834cd3da2a744441e70e524" +"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" From b39a8a29b970f7aa68ea8d957ab9180b9867acb6 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 30 Sep 2017 18:10:30 -0600 Subject: [PATCH 19/43] Allow variables in arguments --- src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 786689f23a..980f95f636 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,11 +35,16 @@ pub fn run(file: &Path) -> Result<()> { for line in data.lines() { let line = line.trim(); if ! line.is_empty() && ! line.starts_with('#') { - let mut args = line.split(' '); + let mut args = line.split(' ').map(|arg| if arg.starts_with('$') { + env::var(&arg[1..]).unwrap_or(String::new()) + } else { + arg.to_string() + }); + if let Some(cmd) = args.next() { - match cmd { + match cmd.as_str() { "cd" => if let Some(dir) = args.next() { - if let Err(err) = env::set_current_dir(dir) { + if let Err(err) = env::set_current_dir(&dir) { println!("init: failed to cd to '{}': {}", dir, err); } } else { @@ -68,7 +73,7 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to export: no argument"); }, "run" => if let Some(new_file) = args.next() { - if let Err(err) = run(&Path::new(new_file)) { + if let Err(err) = run(&Path::new(&new_file)) { println!("init: failed to run '{}': {}", new_file, err); } } else { @@ -76,7 +81,7 @@ pub fn run(file: &Path) -> Result<()> { }, "run.d" => if let Some(new_dir) = args.next() { let mut entries = vec![]; - match read_dir(new_dir) { + match read_dir(&new_dir) { Ok(list) => for entry_res in list { match entry_res { Ok(entry) => { From 57ce75e297f656289ea524ac616037ae3279ec47 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 4 Oct 2017 20:29:41 -0600 Subject: [PATCH 20/43] Update Cargo.lock --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f18a23034..966a233d6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" +"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" From c94d54352914d4dc5d60015dae094de1784a1189 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 9 Oct 2017 20:47:11 -0600 Subject: [PATCH 21/43] Utilize null namespace --- Cargo.lock | 6 +++--- src/main.rs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f18a23034..966a233d6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" +"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" diff --git a/src/main.rs b/src/main.rs index 980f95f636..745d16f57a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,6 +141,8 @@ pub fn main() { println!("init: failed to run initfs:etc/init.rc: {}", err); } + syscall::setrens(0, 0).expect("init: failed to enter null namespace"); + loop { let mut status = 0; syscall::waitpid(0, &mut status, 0).unwrap(); From 9311987d2a64a67028ec306f302038c4d23ca044 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 20 Oct 2017 20:08:02 -0600 Subject: [PATCH 22/43] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..5deeece4f4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Redox OS + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From ed2111b54efc4930f62aee40209b8970a327f403 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 14 Oct 2018 19:56:31 -0600 Subject: [PATCH 23/43] Update Cargo.lock --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 966a233d6d..d7a8ab4e8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,14 +1,14 @@ -[root] +[[package]] name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.31" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" +"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" From 6bab760a654ee7c1f8ffe7d3378b9ff1d477b025 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 8 Jan 2019 20:18:10 -0700 Subject: [PATCH 24/43] Update lock file --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7a8ab4e8b..f8d4890738 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.40" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" +"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" From 958b3046e9a0847b07fa98baa186266cdd9b67a9 Mon Sep 17 00:00:00 2001 From: SamwiseFilmore Date: Thu, 17 Jan 2019 00:03:23 +0000 Subject: [PATCH 25/43] Preliminary Readme --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000..fb145afaad --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# RedoxOS init +This repository contains the init system for RedoxOS. + +Init is currently being rewritten to support a couple of behaviors that are helpful for running a configurable and robust system. These include: +- Dependency relationships between services +- Parallel service startup and shutdown +- Configuration files for each service, including: + - Dependencies + - Methods + - TODO: Users/Groups for services + - TODO: Scheme namespaces for services +- Service management + - Enable and disable services + - Restart failed services From 1e86998534c4fba79ea341e2781f6b0bc4fd64e7 Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Wed, 27 Feb 2019 12:03:13 +0000 Subject: [PATCH 26/43] Update Cargo.lock --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8d4890738..cf11d8bcfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.50" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" +"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" From 396750c2da1f853e6556c264da75ff57a7af9452 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 23 Apr 2019 13:45:20 -0600 Subject: [PATCH 27/43] Fixes for building with Redox in the unix target family --- Cargo.lock | 2 ++ src/main.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf11d8bcfc..f49f7542da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "init" version = "0.1.0" diff --git a/src/main.rs b/src/main.rs index 745d16f57a..4d721e2ca0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,25 +5,25 @@ extern crate syscall; use std::env; use std::fs::{File, read_dir}; use std::io::{Read, Error, Result}; -use std::os::unix::io::{AsRawFd, FromRawFd}; +use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::path::Path; use std::process::Command; use syscall::flag::{O_RDONLY, O_WRONLY}; fn switch_stdio(stdio: &str) -> Result<()> { let stdin = unsafe { File::from_raw_fd( - syscall::open(stdio, O_RDONLY).map_err(|err| Error::from_raw_os_error(err.errno))? + syscall::open(stdio, O_RDONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd ) }; let stdout = unsafe { File::from_raw_fd( - syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? + syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd ) }; let stderr = unsafe { File::from_raw_fd( - syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? + syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd ) }; - syscall::dup2(stdin.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; - syscall::dup2(stdout.as_raw_fd(), 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; - syscall::dup2(stderr.as_raw_fd(), 2, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + syscall::dup2(stdin.as_raw_fd() as usize, 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + syscall::dup2(stdout.as_raw_fd() as usize, 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + syscall::dup2(stderr.as_raw_fd() as usize, 2, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; Ok(()) } From ec060cca50781c2536ce89c666a410502535747b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 2 Aug 2020 15:27:33 -0600 Subject: [PATCH 28/43] Update syscall --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f49f7542da..271d6e0fe1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,13 +4,13 @@ name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.51" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" From fc657b5c23226d15e2e36b06afcf0c0a05e91a98 Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Fri, 15 Jan 2021 18:00:45 +0000 Subject: [PATCH 29/43] Syscall dependency version bump + Fix build breakage Breakage needed use of WaitFlags. --- Cargo.toml | 2 +- src/main.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 955abf76ae..9975559d18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ name = "init" version = "0.1.0" [dependencies] -redox_syscall = "0.1" +redox_syscall = "0.2" diff --git a/src/main.rs b/src/main.rs index 4d721e2ca0..1e2bfc2fbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::io::{Read, Error, Result}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::path::Path; use std::process::Command; -use syscall::flag::{O_RDONLY, O_WRONLY}; +use syscall::flag::{WaitFlags, O_RDONLY, O_WRONLY}; fn switch_stdio(stdio: &str) -> Result<()> { let stdin = unsafe { File::from_raw_fd( @@ -145,6 +145,6 @@ pub fn main() { loop { let mut status = 0; - syscall::waitpid(0, &mut status, 0).unwrap(); + syscall::waitpid(0, &mut status, WaitFlags::empty()).unwrap(); } } From 7e735ba11eee13f6220b214c3b161094c07571dd Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 28 Apr 2021 20:57:08 -0600 Subject: [PATCH 30/43] Update dependencies --- Cargo.lock | 15 ++++++++++++--- Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 271d6e0fe1..741924cadd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,16 +1,25 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.57" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [metadata] -"checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" diff --git a/Cargo.toml b/Cargo.toml index 9975559d18..3426f6eb70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ name = "init" version = "0.1.0" [dependencies] -redox_syscall = "0.2" +redox_syscall = "0.2.7" From 21c62fd61f2abb2138cec7d680a46d7ff615f68f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 5 May 2021 21:14:49 -0600 Subject: [PATCH 31/43] Allow character devices to be used as run input --- src/main.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1e2bfc2fbc..a99488a435 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,8 @@ -#![deny(warnings)] - extern crate syscall; use std::env; use std::fs::{File, read_dir}; -use std::io::{Read, Error, Result}; +use std::io::{BufReader, BufRead, Error, Result}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::path::Path; use std::process::Command; @@ -29,11 +27,11 @@ fn switch_stdio(stdio: &str) -> Result<()> { } pub fn run(file: &Path) -> Result<()> { - let mut data = String::new(); - File::open(file)?.read_to_string(&mut data)?; - - for line in data.lines() { - let line = line.trim(); + let file = File::open(file)?; + let reader = BufReader::new(file); + for line_res in reader.lines() { + let line_raw = line_res?; + let line = line_raw.trim(); if ! line.is_empty() && ! line.starts_with('#') { let mut args = line.split(' ').map(|arg| if arg.starts_with('$') { env::var(&arg[1..]).unwrap_or(String::new()) From db3ae355bc5bf06fc1a44b2a1261536a6039d2a1 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Jun 2021 14:34:23 +0200 Subject: [PATCH 32/43] Update syscall. --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 741924cadd..1067b153ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,12 +9,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -22,4 +22,4 @@ dependencies = [ [metadata] "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" +"checksum redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" diff --git a/Cargo.toml b/Cargo.toml index 3426f6eb70..6b9dfe4026 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ name = "init" version = "0.1.0" [dependencies] -redox_syscall = "0.2.7" +redox_syscall = "0.2.9" From 44f7557f1277ed5994e83c76bf5ee181067b9f8b Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 25 Mar 2022 15:07:06 +0100 Subject: [PATCH 33/43] Update syscall --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1067b153ae..0e759e3660 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,25 +1,25 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "init" version = "0.1.0" dependencies = [ - "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall", ] [[package]] name = "redox_syscall" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", ] - -[metadata] -"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" diff --git a/Cargo.toml b/Cargo.toml index 6b9dfe4026..6783bf9e44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ name = "init" version = "0.1.0" [dependencies] -redox_syscall = "0.2.9" +redox_syscall = "0.2.12" From 0c87d80852a6c44c608a4f395b44f2e548398f5d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 26 Jul 2022 16:13:20 -0600 Subject: [PATCH 34/43] Update Cargo.lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e759e3660..475f70d9ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,9 +17,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.12" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] From 6386fe126c50580170e97e9fcb34ab654fc1f672 Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Thu, 6 Jul 2023 10:15:12 +1000 Subject: [PATCH 35/43] init: misc changes for GPU drivers Signed-off-by: Anhad Singh --- src/main.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main.rs b/src/main.rs index a99488a435..a389d5eb48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,6 +78,36 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to run: no argument"); }, "run.d" => if let Some(new_dir) = args.next() { + // On startup, the VESA display driver is started which basically makes use of the framebuffer + // provided by the firmware. The GPU device are latter started by `pcid` (such as `virtio-gpu`). + let mut devices = vec![]; + let schemes = std::fs::read_dir(":").unwrap(); + + for entry in schemes { + let path = entry.unwrap().path(); + let path_str = path + .into_os_string() + .into_string() + .expect("init: failed to convert path to string"); + + if path_str.contains("display") { + println!("init: found display scheme {}", path_str); + devices.push(path_str); + } + } + + let device = devices.iter().filter(|d| !d.contains("vesa")).collect::>(); + let device = if device.is_empty() { + // No GPU available, fallback to VESA display which *should* always be accessible. + "vesa" + } else { + // :/display/virtio-gpu + // ^^^^^^^^^^ + device[0].split("/").nth(2).unwrap() + }; + + std::env::set_var("DISPLAY", &format!("display/{}:3/activate", device)); + let mut entries = vec![]; match read_dir(&new_dir) { Ok(list) => for entry_res in list { From d038cfea2c8381655273858fdc29d4d8676d61d4 Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Thu, 3 Aug 2023 11:34:51 +1000 Subject: [PATCH 36/43] init: set the `DISPLAY` environment variable to the VT# Signed-off-by: Anhad Singh --- src/main.rs | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/main.rs b/src/main.rs index a389d5eb48..b2834a4f39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,35 +78,7 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to run: no argument"); }, "run.d" => if let Some(new_dir) = args.next() { - // On startup, the VESA display driver is started which basically makes use of the framebuffer - // provided by the firmware. The GPU device are latter started by `pcid` (such as `virtio-gpu`). - let mut devices = vec![]; - let schemes = std::fs::read_dir(":").unwrap(); - - for entry in schemes { - let path = entry.unwrap().path(); - let path_str = path - .into_os_string() - .into_string() - .expect("init: failed to convert path to string"); - - if path_str.contains("display") { - println!("init: found display scheme {}", path_str); - devices.push(path_str); - } - } - - let device = devices.iter().filter(|d| !d.contains("vesa")).collect::>(); - let device = if device.is_empty() { - // No GPU available, fallback to VESA display which *should* always be accessible. - "vesa" - } else { - // :/display/virtio-gpu - // ^^^^^^^^^^ - device[0].split("/").nth(2).unwrap() - }; - - std::env::set_var("DISPLAY", &format!("display/{}:3/activate", device)); + std::env::set_var("DISPLAY", "3"); let mut entries = vec![]; match read_dir(&new_dir) { From 3e14cb4017261a71cb7906dce619bc23c9a8116b Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sat, 4 Nov 2023 16:12:35 +0100 Subject: [PATCH 37/43] Switch to libredox --- Cargo.lock | 29 ++++++++- Cargo.toml | 4 +- src/main.rs | 180 +++++++++++++++++++++++++++++----------------------- 3 files changed, 129 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 475f70d9ae..1105e4951e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,18 +8,41 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "init" version = "0.1.0" dependencies = [ + "libredox", +] + +[[package]] +name = "libc" +version = "0.2.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" + +[[package]] +name = "libredox" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" +dependencies = [ + "bitflags 2.4.1", + "libc", "redox_syscall", ] [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] diff --git a/Cargo.toml b/Cargo.toml index 6783bf9e44..a71a34ff22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "init" version = "0.1.0" +edition = "2021" +license = "MIT" [dependencies] -redox_syscall = "0.2.12" +libredox = "0.0.2" diff --git a/src/main.rs b/src/main.rs index b2834a4f39..1d94afc503 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,27 +1,28 @@ -extern crate syscall; - use std::env; -use std::fs::{File, read_dir}; -use std::io::{BufReader, BufRead, Error, Result}; -use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; +use std::fs::{read_dir, File}; +use std::io::{BufRead, BufReader, Error, Result}; use std::path::Path; use std::process::Command; -use syscall::flag::{WaitFlags, O_RDONLY, O_WRONLY}; + +use libredox::flag::{O_RDONLY, O_WRONLY}; fn switch_stdio(stdio: &str) -> Result<()> { - let stdin = unsafe { File::from_raw_fd( - syscall::open(stdio, O_RDONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd - ) }; - let stdout = unsafe { File::from_raw_fd( - syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd - ) }; - let stderr = unsafe { File::from_raw_fd( - syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd - ) }; + let stdin = libredox::Fd::open(stdio, O_RDONLY, 0) + .map_err(|err| Error::from_raw_os_error(err.errno))?; + let stdout = libredox::Fd::open(stdio, O_WRONLY, 0) + .map_err(|err| Error::from_raw_os_error(err.errno))?; + let stderr = libredox::Fd::open(stdio, O_WRONLY, 0) + .map_err(|err| Error::from_raw_os_error(err.errno))?; - syscall::dup2(stdin.as_raw_fd() as usize, 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; - syscall::dup2(stdout.as_raw_fd() as usize, 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; - syscall::dup2(stderr.as_raw_fd() as usize, 2, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?; + stdin + .dup2(0, &[]) + .map_err(|err| Error::from_raw_os_error(err.errno))?; + stdout + .dup2(1, &[]) + .map_err(|err| Error::from_raw_os_error(err.errno))?; + stderr + .dup2(2, &[]) + .map_err(|err| Error::from_raw_os_error(err.errno))?; Ok(()) } @@ -32,22 +33,26 @@ pub fn run(file: &Path) -> Result<()> { for line_res in reader.lines() { let line_raw = line_res?; let line = line_raw.trim(); - if ! line.is_empty() && ! line.starts_with('#') { - let mut args = line.split(' ').map(|arg| if arg.starts_with('$') { - env::var(&arg[1..]).unwrap_or(String::new()) - } else { - arg.to_string() + if !line.is_empty() && !line.starts_with('#') { + let mut args = line.split(' ').map(|arg| { + if arg.starts_with('$') { + env::var(&arg[1..]).unwrap_or(String::new()) + } else { + arg.to_string() + } }); if let Some(cmd) = args.next() { match cmd.as_str() { - "cd" => if let Some(dir) = args.next() { - if let Err(err) = env::set_current_dir(&dir) { - println!("init: failed to cd to '{}': {}", dir, err); + "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"); } - } else { - println!("init: failed to cd: no argument"); - }, + } "echo" => { if let Some(arg) = args.next() { print!("{}", arg); @@ -56,64 +61,77 @@ pub fn run(file: &Path) -> Result<()> { print!(" {}", arg); } print!("\n"); - }, - "export" => if let Some(var) = args.next() { - let mut value = String::new(); - if let Some(arg) = args.next() { - value.push_str(&arg); + } + "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"); } - for arg in args { - value.push(' '); - value.push_str(&arg); + } + "run" => { + if let Some(new_file) = args.next() { + 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"); } - 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(&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() { - std::env::set_var("DISPLAY", "3"); + } + "run.d" => { + if let Some(new_dir) = args.next() { + std::env::set_var("DISPLAY", "3"); - let mut entries = vec![]; - match read_dir(&new_dir) { - Ok(list) => 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); + let mut entries = vec![]; + match read_dir(&new_dir) { + Ok(list) => { + 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 + ); + } + } } } - }, - Err(err) => { - println!("init: failed to run.d: '{}': {}", new_dir, err); + Err(err) => { + println!("init: failed to run.d: '{}': {}", new_dir, err); + } } - } - entries.sort(); + entries.sort(); - for entry in entries { - if let Err(err) = run(&entry) { - println!("init: failed to run '{}': {}", entry.display(), err); + for entry in entries { + if let Err(err) = run(&entry) { + println!("init: failed to run '{}': {}", entry.display(), err); + } } + } else { + println!("init: failed to run.d: no argument"); } - } else { - println!("init: failed to run.d: no argument"); - }, - "stdio" => if let Some(stdio) = args.next() { - if let Err(err) = switch_stdio(&stdio) { - println!("init: failed to switch stdio to '{}': {}", stdio, err); + } + "stdio" => { + if let Some(stdio) = args.next() { + if let Err(err) = switch_stdio(&stdio) { + println!("init: failed to switch stdio to '{}': {}", stdio, err); + } + } else { + println!("init: failed to set stdio: no argument"); } - } else { - println!("init: failed to set stdio: no argument"); - }, + } _ => { let mut command = Command::new(cmd); for arg in args { @@ -123,9 +141,11 @@ pub fn run(file: &Path) -> Result<()> { 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 wait for '{}': {}", line, err) + } }, - Err(err) => println!("init: failed to execute '{}': {}", line, err) + Err(err) => println!("init: failed to execute '{}': {}", line, err), } } } @@ -141,10 +161,10 @@ pub fn main() { println!("init: failed to run initfs:etc/init.rc: {}", err); } - syscall::setrens(0, 0).expect("init: failed to enter null namespace"); + libredox::call::setrens(0, 0).expect("init: failed to enter null namespace"); loop { let mut status = 0; - syscall::waitpid(0, &mut status, WaitFlags::empty()).unwrap(); + libredox::call::waitpid(0, &mut status, 0).unwrap(); } } From 89ee1b4d66b57fe839045f7082dbd2364afdc7de Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 7 Jan 2024 18:09:53 +0100 Subject: [PATCH 38/43] Allow specifying multiple search dirs for run.d The entries in the search dirs will be merged with the entry in the last search dir taking priority in case multiple entries have the same name. This allows putting system init configs in /usr/lib/init.d while the user can overwrite it by placing a file with the same name in /etc/init.d --- src/main.rs | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1d94afc503..4ddb494549 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use std::collections::BTreeMap; use std::env; use std::fs::{read_dir, File}; use std::io::{BufRead, BufReader, Error, Result}; @@ -87,16 +88,26 @@ pub fn run(file: &Path) -> Result<()> { } } "run.d" => { - if let Some(new_dir) = args.next() { - std::env::set_var("DISPLAY", "3"); + // This must be a BTreeMap to iterate in sorted order. + let mut entries = BTreeMap::new(); + let mut missing_arg = true; + + for new_dir in args { + if !Path::new(&new_dir).exists() { + // Skip non-existent dirs + continue; + } + missing_arg = false; - let mut entries = vec![]; match read_dir(&new_dir) { Ok(list) => { for entry_res in list { match entry_res { Ok(entry) => { - entries.push(entry.path()); + // This intentionally overwrites older entries with + // the same filename to allow overriding entries in + // one search dir with those in a later search dir. + entries.insert(entry.file_name(), entry.path()); } Err(err) => { println!( @@ -111,16 +122,22 @@ pub fn run(file: &Path) -> Result<()> { 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); + if missing_arg { + println!("init: failed to run.d: no argument or all dirs are non-existent"); + } else { + std::env::set_var("DISPLAY", "3"); + // This takes advantage of BTreeMap iterating in sorted order. + for (_, entry_path) in entries { + if let Err(err) = run(&entry_path) { + println!( + "init: failed to run '{}': {}", + entry_path.display(), + err + ); } } - } else { - println!("init: failed to run.d: no argument"); } } "stdio" => { From ec04d52c7e2880de5c0544608baf1c8becfd175b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 18 Jan 2024 15:09:15 -0700 Subject: [PATCH 39/43] Add unset builtin and update config path --- src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4ddb494549..489bb9200a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,6 +149,11 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to set stdio: no argument"); } } + "unset" => { + for arg in args { + env::remove_var(&arg); + } + } _ => { let mut command = Command::new(cmd); for arg in args { @@ -174,8 +179,9 @@ pub fn run(file: &Path) -> Result<()> { } pub fn main() { - if let Err(err) = run(&Path::new("initfs:etc/init.rc")) { - println!("init: failed to run initfs:etc/init.rc: {}", err); + let config = "/scheme/initfs/etc/init.rc"; + if let Err(err) = run(&Path::new(config)) { + println!("init: failed to run {}: {}", config, err); } libredox::call::setrens(0, 0).expect("init: failed to enter null namespace"); From 050febc94fe7d84bea51a462e9cae1433837c8d6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:45:41 +0200 Subject: [PATCH 40/43] Don't set the DISPLAY env var This is the only case where init sets an env var without the user instructing it to do so, making it hard to trace back where the env var originated from. It also only sets it for processes spawned after the first run.d command for whatever reason. And finally not setting DISPLAY avoids hard coding knowledge about unrelated system components. --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 489bb9200a..49c559b6ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,6 @@ pub fn run(file: &Path) -> Result<()> { if missing_arg { println!("init: failed to run.d: no argument or all dirs are non-existent"); } else { - std::env::set_var("DISPLAY", "3"); // This takes advantage of BTreeMap iterating in sorted order. for (_, entry_path) in entries { if let Err(err) = run(&entry_path) { From 23fa812de1eca6354a26a9d60e3b0d2172fc91d5 Mon Sep 17 00:00:00 2001 From: Kamil Koczurek Date: Fri, 20 Sep 2024 21:03:04 +0200 Subject: [PATCH 41/43] Use set_default_scheme to control resolution of absolute paths --- src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 49c559b6ba..5b557c470a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,33 @@ use std::collections::BTreeMap; use std::env; +use std::ffi::CString; use std::fs::{read_dir, File}; -use std::io::{BufRead, BufReader, Error, Result}; +use std::io::{BufRead, BufReader, Error, Result, Write}; use std::path::Path; use std::process::Command; +use libredox::error::Error as OsError; + use libredox::flag::{O_RDONLY, O_WRONLY}; +fn set_default_scheme(scheme: &str) -> std::result::Result<(), OsError> { + use std::ffi::{c_char, c_int}; + + extern "C" { + fn set_default_scheme(scheme: *const c_char) -> c_int; + } + + let cstr = + CString::new(scheme.as_bytes()).expect(&format!("init: invalid default scheme {}", scheme)); + + let res = unsafe { set_default_scheme(cstr.as_ptr()) }; + + match res { + 0 => Ok(()), + error_code => Err(OsError::new(error_code)), + } +} + fn switch_stdio(stdio: &str) -> Result<()> { let stdin = libredox::Fd::open(stdio, O_RDONLY, 0) .map_err(|err| Error::from_raw_os_error(err.errno))?; @@ -54,6 +75,18 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to cd: no argument"); } } + "set-default-scheme" => { + if let Some(scheme) = args.next() { + if let Err(err) = set_default_scheme(&scheme) { + println!( + "init: failed to set default scheme to '{}': {}", + scheme, err + ); + } + } else { + println!("init: failed to set default scheme: no argument"); + } + } "echo" => { if let Some(arg) = args.next() { print!("{}", arg); @@ -125,7 +158,9 @@ pub fn run(file: &Path) -> Result<()> { } if missing_arg { - println!("init: failed to run.d: no argument or all dirs are non-existent"); + println!( + "init: failed to run.d: no argument or all dirs are non-existent" + ); } else { // This takes advantage of BTreeMap iterating in sorted order. for (_, entry_path) in entries { @@ -154,14 +189,22 @@ pub fn run(file: &Path) -> Result<()> { } } _ => { - let mut command = Command::new(cmd); + let mut command = Command::new(cmd.clone()); 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()), + Ok(child) => match child.wait_with_output() { + Ok(output) => { + std::io::stdout() + .write_all(output.stdout.as_slice()) + .unwrap(); + std::io::stderr() + .write_all(output.stderr.as_slice()) + .unwrap(); + println!("{cmd} done."); + } Err(err) => { println!("init: failed to wait for '{}': {}", line, err) } @@ -178,7 +221,11 @@ pub fn run(file: &Path) -> Result<()> { } pub fn main() { - let config = "/scheme/initfs/etc/init.rc"; + if let Err(err) = set_default_scheme("initfs") { + println!("init: failed to set default scheme: {}", err); + } + + let config = "/etc/init.rc"; if let Err(err) = run(&Path::new(config)) { println!("init: failed to run {}: {}", config, err); } From b465daf51881ea3dcf01b1e4c074a5f80e74f27c Mon Sep 17 00:00:00 2001 From: Andrey Turkin Date: Thu, 18 Jul 2024 13:50:11 +0300 Subject: [PATCH 42/43] Bump dependencies --- Cargo.lock | 26 ++++++++++---------------- Cargo.toml | 2 +- src/main.rs | 23 +++++++---------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1105e4951e..9ec341303e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,15 +4,9 @@ version = 3 [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "init" @@ -23,26 +17,26 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.149" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libredox" -version = "0.0.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.1", + "bitflags", "libc", "redox_syscall", ] [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index a71a34ff22..1c2eee4630 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" license = "MIT" [dependencies] -libredox = "0.0.2" +libredox = "0.1" diff --git a/src/main.rs b/src/main.rs index 5b557c470a..8b8eef158f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::env; use std::ffi::CString; use std::fs::{read_dir, File}; -use std::io::{BufRead, BufReader, Error, Result, Write}; +use std::io::{BufRead, BufReader, Result, Write}; use std::path::Path; use std::process::Command; @@ -29,22 +29,13 @@ fn set_default_scheme(scheme: &str) -> std::result::Result<(), OsError> { } fn switch_stdio(stdio: &str) -> Result<()> { - let stdin = libredox::Fd::open(stdio, O_RDONLY, 0) - .map_err(|err| Error::from_raw_os_error(err.errno))?; - let stdout = libredox::Fd::open(stdio, O_WRONLY, 0) - .map_err(|err| Error::from_raw_os_error(err.errno))?; - let stderr = libredox::Fd::open(stdio, O_WRONLY, 0) - .map_err(|err| Error::from_raw_os_error(err.errno))?; + let stdin = libredox::Fd::open(stdio, O_RDONLY, 0)?; + let stdout = libredox::Fd::open(stdio, O_WRONLY, 0)?; + let stderr = libredox::Fd::open(stdio, O_WRONLY, 0)?; - stdin - .dup2(0, &[]) - .map_err(|err| Error::from_raw_os_error(err.errno))?; - stdout - .dup2(1, &[]) - .map_err(|err| Error::from_raw_os_error(err.errno))?; - stderr - .dup2(2, &[]) - .map_err(|err| Error::from_raw_os_error(err.errno))?; + stdin.dup2(0, &[])?; + stdout.dup2(1, &[])?; + stderr.dup2(2, &[])?; Ok(()) } From 0e7a0d3ab46817915180adbbb775c76d67fee31c Mon Sep 17 00:00:00 2001 From: Ribbon Date: Thu, 9 Jan 2025 12:12:09 +0000 Subject: [PATCH 43/43] Document how to contribute and do development in the README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index fb145afaad..bfa86d6df4 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,19 @@ Init is currently being rewritten to support a couple of behaviors that are help - Service management - Enable and disable services - Restart failed services + +## How To Contribute + +To learn how to contribute to this system component you need to read the following document: + +- [CONTRIBUTING.md](https://gitlab.redox-os.org/redox-os/redox/-/blob/master/CONTRIBUTING.md) + +## Development + +To learn how to do development with this system component inside the Redox build system you need to read the [Build System](https://doc.redox-os.org/book/build-system-reference.html) and [Coding and Building](https://doc.redox-os.org/book/coding-and-building.html) pages. + +### How To Build + +To build this system component you need to download the Redox build system, you can learn how to do it on the [Building Redox](https://doc.redox-os.org/book/podman-build.html) page. + +This is necessary because they only work with cross-compilation to a Redox virtual machine, but you can do some testing from Linux.