From f80b51411bd642e3f1528b1c460be2e992310893 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Tue, 30 Jun 2026 12:14:52 +0700 Subject: [PATCH] init: Change cwd to `/` at boot --- init/src/main.rs | 13 ++++++++++++- init/src/script.rs | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/init/src/main.rs b/init/src/main.rs index 5682cf4455..ef89ee1b72 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -29,6 +29,7 @@ struct InitConfig { log_debug: bool, skip_cmd: Vec, envs: BTreeMap, + cwd: OsString, } impl InitConfig { @@ -44,11 +45,18 @@ impl InitConfig { log_debug, skip_cmd, envs: BTreeMap::from([("RUST_BACKTRACE".to_owned(), "1".into())]), + cwd: "/scheme/initfs".into(), } } } -fn switch_root(unit_store: &mut UnitStore, config: &mut InitConfig, prefix: &Path, etcdir: &Path) { +fn switch_root( + unit_store: &mut UnitStore, + config: &mut InitConfig, + prefix: &Path, + etcdir: &Path, + cwd: &Path, +) { eprintln!( "init: switchroot to {} {}", prefix.display(), @@ -62,6 +70,7 @@ fn switch_root(unit_store: &mut UnitStore, config: &mut InitConfig, prefix: &Pat "LD_LIBRARY_PATH".to_owned(), prefix.join("lib").into_os_string(), ); + config.cwd = cwd.to_path_buf().into_os_string(); unit_store.config_dirs = vec![prefix.join("lib").join("init.d"), etcdir.join("init.d")]; @@ -122,6 +131,7 @@ fn main() { &mut init_config, Path::new("/scheme/initfs"), Path::new("/scheme/initfs/etc"), + Path::new("/scheme/initfs"), ); // Start logd first such that we can pass /scheme/log as stdio to all other services @@ -145,6 +155,7 @@ fn main() { &mut init_config, Path::new("/usr"), Path::new("/etc"), + Path::new("/"), ); { // FIXME introduce multi-user.target unit and replace the config dir iteration diff --git a/init/src/script.rs b/init/src/script.rs index d18e3a045b..5315b39a32 100644 --- a/init/src/script.rs +++ b/init/src/script.rs @@ -97,6 +97,7 @@ impl Command { command.args(process.args.iter().map(|arg| subst_env(arg))); command.env_clear(); command.envs(&config.envs).envs(&process.envs); + command.current_dir(&config.cwd); let mut child = match command.spawn() { Ok(child) => child,