init: Introduce switchroot command

This sets PATH, LD_LIBRARY_PATH and runs init scripts for the new root.
In the future this could replace the entire set of services that should
run, restarting any services for which a newer executable is available
in the new root and stopping any services which don't exist in the new
root. This behavior could also be useful for soft-reboots in the future
to handle updates without rebooting the entire system.
This commit is contained in:
bjorn3
2026-02-19 20:18:07 +01:00
parent a5168828ad
commit 0227c0677c
5 changed files with 45 additions and 44 deletions
+12 -10
View File
@@ -48,7 +48,7 @@ pub enum Command {
// Misc
Echo(String),
RunD(Vec<PathBuf>),
SwitchRoot(PathBuf, PathBuf),
Nothing,
}
@@ -80,15 +80,17 @@ impl Command {
}
Ok(Command::Export(var, value))
}
"run.d" => {
let args = args.map(|arg| PathBuf::from(arg)).collect::<Vec<_>>();
if args.is_empty() {
return Err(
"init: failed to run.d: no argument or all dirs are non-existent"
.to_owned(),
);
}
Ok(Command::RunD(args))
"switchroot" => {
let Some(prefix) = args.next() else {
return Err("init: failed to switchroot: no argument".to_owned());
};
let Some(etcdir) = args.next() else {
return Err("init: failed to switchroot: missing etcdir".to_owned());
};
Ok(Command::SwitchRoot(
PathBuf::from(prefix),
PathBuf::from(etcdir),
))
}
"stdio" => {
let Some(stdio) = args.next() else {