diff --git a/Cargo.lock b/Cargo.lock index 29f624784b9018b7cfd50d532ae305109bca23ad..911e8f1ef1c5ccddd4907b3427125bfbe2e7470a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,11 +30,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "init" version = "0.1.0" dependencies = [ - "libc", "nix", - "signal-hook", - "signal-hook-registry", - "utils", ] [[package]] @@ -69,26 +65,6 @@ dependencies = [ name = "process1" version = "0.1.0" -[[package]] -name = "signal-hook" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c98891d737e271a2954825ef19e46bd16bdb98e2746f2eec4f7a4ef7946efd1" -dependencies = [ - "cc", - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" -dependencies = [ - "libc", -] - [[package]] name = "systemd" version = "0.1.0" @@ -96,7 +72,3 @@ version = "0.1.0" [[package]] name = "tests" version = "0.1.0" - -[[package]] -name = "utils" -version = "0.1.0" diff --git a/Dockerfile b/Dockerfile index a9fa90c5722bf9be82cde6d047834b33a4f78cbb..1773dd7a639f86c299affee9b069b2db981f197f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ - FROM scratch -#ADD target/x86_64-unknown-linux-musl/debug/process1 /sbin/init COPY target/x86_64-unknown-linux-musl/debug/init /sbin/init COPY target/x86_64-unknown-linux-musl/debug/process1 /usr/lib/process1/process1 -COPY target/x86_64-unknown-linux-musl/debug/systemd /usr/lib/systemd/systemd +#COPY target/x86_64-unknown-linux-musl/debug/systemd /usr/lib/systemd/systemd CMD ["/sbin/init"] diff --git a/src/init/Cargo.toml b/src/init/Cargo.toml index e478f26a3e3e96eb674ada372f703278a9197adb..5eb19113162e05b9625f5f42891736ce93d9f36e 100644 --- a/src/init/Cargo.toml +++ b/src/init/Cargo.toml @@ -7,8 +7,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -signal-hook = { version = "0.3.7", features = ["extended-siginfo"] } -signal-hook-registry = "*" -utils = { path = "../utils" } -libc = { version = "^0.2" } -nix = "0.23.0" +nix = "0.23.0" \ No newline at end of file diff --git a/src/init/src/main.rs b/src/init/src/main.rs index d4aedec0d3b82cddea835d3c0fcfe5fd86725349..1d794b70d7f777bc0ee338b05f05cd4d6a418208 100644 --- a/src/init/src/main.rs +++ b/src/init/src/main.rs @@ -2,28 +2,19 @@ use std::io::Error; use std::path::Path; use std::process::Command; -use nix::sys::wait; +use nix::unistd::Pid; +use nix::sys::wait::waitpid; use nix::sys::wait::WaitPidFlag; -const PROCESS1_PATH: &str = "/usr/lib/process1/process1"; -const SYSTEMD_PATH: &str = "/usr/lib/systemd/systemd"; - -#[derive(Debug)] -enum Proc1Error { - IOError(Error), -} - -impl std::convert::From for Proc1Error { - fn from(e: std::io::Error) -> Self { - Proc1Error::IOError(e) - } -} +const PROCESS1_PATH: &'static str = "/usr/lib/process1/process1"; +const SYSTEMD_PATH: &'static str = "/usr/lib/systemd/systemd"; fn main() { let cmd = match get_command() { Some(cmd) => cmd, None => detect_init(), }; + loop { if execute_mode(&cmd).is_ok() { break; @@ -32,18 +23,25 @@ fn main() { } fn get_command() -> Option { + if std::env::args().count() > 2 { + panic!("More than one para, panic!!!"); + } + std::env::args().nth(1) } fn detect_init() -> String { if Path::new(PROCESS1_PATH).exists() { return String::from(PROCESS1_PATH); + } else if Path::new(SYSTEMD_PATH).exists() { + return String::from(SYSTEMD_PATH); } - String::from(SYSTEMD_PATH) + + String::new() } -fn execute_mode(s: &String) -> Result<(), Proc1Error> { - println!("running to execute specific command {:?}", s); +fn execute_mode(s: &String) -> Result<(), Error> { + println!("Running to execute command : {:?}", s); let mut command = Command::new(s); let mut child = command.spawn()?; @@ -52,10 +50,10 @@ fn execute_mode(s: &String) -> Result<(), Proc1Error> { match result { Ok(Some(status)) => { if status.success() { - println!("successfully finished"); // shutdown + println!("Successfully finished"); // shutdown break; } else { - println!("exited with error"); + println!("Exited with error, Again"); child = command.spawn()?; } } @@ -67,7 +65,7 @@ fn execute_mode(s: &String) -> Result<(), Proc1Error> { } fn reap_zombie() { - let _result = wait::waitpid(nix::unistd::Pid::from_raw(-1), + let _result = waitpid(Pid::from_raw(-1), Some(WaitPidFlag::WNOHANG)); send_signal() }