diff --git a/rust/src/init/main.rs b/rust/src/init/main.rs index ba6a622..4e37548 100644 --- a/rust/src/init/main.rs +++ b/rust/src/init/main.rs @@ -1,6 +1,6 @@ extern crate libc; -use std::io; +use std::{io, fs}; use std::process::{self, Child,Command,Stdio}; use std::os::unix::process::CommandExt; @@ -65,6 +65,10 @@ fn setup_mounts() -> io::Result<()> { mount_devtmpfs("/dev")?; mkdir("/dev/pts")?; mount_devpts("/dev/pts")?; + match mount_9p("home", "/home/user") { + Ok(()) => { println!("Home mounted at /home/user") }, + Err(e) => { println!("Mount of home failed: {}", e) } + } Ok(()) } @@ -77,7 +81,7 @@ fn setup() -> io::Result<()> { Ok(()) } -fn run_shell() -> io::Result{ +unsafe fn run_shell() -> io::Result{ Command::new("/bin/bash") .env_clear() .env("TERM", "xterm-256color") @@ -85,7 +89,7 @@ fn run_shell() -> io::Result{ .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) - .before_exec(|| {println!("{}", SPLASH);Ok(())}) + .pre_exec(|| {println!("{}", SPLASH);Ok(())}) .spawn() } @@ -109,12 +113,27 @@ fn wait_for_child() -> i32 { } handle_waitpid_err(r.err().unwrap()); } +fn is_run_systemd() -> bool { + let cmdline = match fs::read_to_string("/proc/cmdline") { + Ok(cmdline) => cmdline, + _ => return false, + }; + cmdline.contains("phinit.run_systemd") +} +fn run_systemd() { + let err = Command::new("/usr/lib/systemd/systemd") + .exec(); + println!("failed to launch systemd: {}", err); +} fn main() { if let Err(err) = setup() { println!("Error on setup(): {:?}", err); return; } - let _child = match run_shell() { + if is_run_systemd() { + run_systemd() + } + let _child = match unsafe { run_shell() } { Ok(child) => child, Err(err) => { println!("Error launching shell: {:?}", err); return; } }; diff --git a/rust/src/init/sys.rs b/rust/src/init/sys.rs index e226dfa..43ad1d2 100644 --- a/rust/src/init/sys.rs +++ b/rust/src/init/sys.rs @@ -34,6 +34,11 @@ pub fn move_mount(source: &str, target: &str) -> io::Result<()> { mount(source, target, "", libc::MS_MOVE, None) } +pub fn mount_9p(name: &str, target: &str) -> io::Result<()> { + const MS_LAZYTIME: libc::c_ulong = (1 << 25); + mount(name, target, "9p", libc::MS_NOATIME|MS_LAZYTIME, Some("trans=virtio,version=9p2000.L,cache=loose")) +} + fn cstr(s: &str) -> CString { CString::new(s).unwrap() @@ -157,6 +162,4 @@ pub fn reboot(cmd: libc::c_int) -> io::Result<()> { } Ok(()) } - - } \ No newline at end of file