Decouple client contracts and close private role registries
This commit is contained in:
parent
786049534d
commit
22325aa76a
5 changed files with 1041 additions and 321 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#![doc = "Runtime construction interfaces owned by the Lazaret Runtime Supervisor."]
|
||||
|
||||
pub mod network;
|
||||
pub mod private_roles;
|
||||
pub mod sandbox;
|
||||
pub mod supervision;
|
||||
|
|
|
|||
|
|
@ -1,24 +1,9 @@
|
|||
fn main() {
|
||||
let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
|
||||
if let Some(result) = lazaret_linux::process::dispatch_private_process_role(&arguments) {
|
||||
if let Err(error) = result {
|
||||
eprintln!("private process role failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(result) = lazaret_ignored_workspace::dispatch_private_router(&arguments) {
|
||||
if let Err(error) = result {
|
||||
eprintln!("ignored workspace router failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(result) =
|
||||
lazaret_runtime_supervisor::supervision::dispatch_private_runtime_role(&arguments)
|
||||
if let Some(outcome) = lazaret_runtime_supervisor::private_roles::REGISTRY.dispatch(&arguments)
|
||||
{
|
||||
if let Err(error) = result {
|
||||
eprintln!("Runtime Supervisor failed: {error}");
|
||||
if let Err(error) = outcome.result {
|
||||
eprintln!("private role {} failed: {error}", outcome.name);
|
||||
std::process::exit(1);
|
||||
}
|
||||
return;
|
||||
|
|
|
|||
30
crates/lazaret-runtime-supervisor/src/private_roles.rs
Normal file
30
crates/lazaret-runtime-supervisor/src/private_roles.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use lazaret_ignored_workspace::{PRIVATE_ROUTER_ROLE, dispatch_private_router};
|
||||
use lazaret_linux::private_role::{PrivateRole, PrivateRoleRegistry};
|
||||
use lazaret_linux::process::{PRIVATE_PROCESS_ROLE, dispatch_private_process_role};
|
||||
|
||||
use crate::supervision::{PRIVATE_RUNTIME_ROLE, dispatch_private_runtime_role};
|
||||
|
||||
static ROLES: [PrivateRole; 3] = [
|
||||
PrivateRole::new(PRIVATE_PROCESS_ROLE, dispatch_private_process_role),
|
||||
PrivateRole::new(PRIVATE_ROUTER_ROLE, dispatch_private_router),
|
||||
PrivateRole::new(PRIVATE_RUNTIME_ROLE, dispatch_private_runtime_role),
|
||||
];
|
||||
|
||||
pub static REGISTRY: PrivateRoleRegistry = PrivateRoleRegistry::new(&ROLES);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn runtime_supervisor_declares_exact_ordered_roles() {
|
||||
assert_eq!(
|
||||
REGISTRY.names(),
|
||||
[
|
||||
PRIVATE_PROCESS_ROLE,
|
||||
PRIVATE_ROUTER_ROLE,
|
||||
PRIVATE_RUNTIME_ROLE
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -604,14 +604,7 @@ impl SandboxBundle {
|
|||
/// # Errors
|
||||
/// Returns an error if the fixed layout violates the configuration layout contract.
|
||||
pub fn default_sandbox_layout() -> Result<SandboxLayoutV1, SandboxBuildError> {
|
||||
SandboxLayoutV1::from_protected_destinations([
|
||||
WORKSPACE_DESTINATION.to_owned(),
|
||||
CONTROL_ROOT_DESTINATION.to_owned(),
|
||||
"/proc".to_owned(),
|
||||
"/sys".to_owned(),
|
||||
"/dev".to_owned(),
|
||||
])
|
||||
.map_err(|error| {
|
||||
SandboxLayoutV1::default_layout().map_err(|error| {
|
||||
SandboxBuildError::new(
|
||||
SandboxBuildErrorKind::InvalidPath,
|
||||
format!("default sandbox layout is invalid: {error}"),
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ use crate::network::{
|
|||
};
|
||||
use crate::sandbox::RunscCommand;
|
||||
|
||||
const PRIVATE_ROLE_ARGUMENT: &str = "--lazaret-runtime-supervisor-role";
|
||||
pub const PRIVATE_RUNTIME_ROLE: &str = "--lazaret-runtime-supervisor-role";
|
||||
const MAX_CONTROL_MESSAGE: usize = 16 * 1024;
|
||||
const READINESS_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
const TERMINATION_GRACE: Duration = Duration::from_secs(2);
|
||||
|
|
@ -415,7 +415,7 @@ impl RuntimeSupervisorLaunch {
|
|||
));
|
||||
}
|
||||
let mut target = TargetCommand::new("/proc/self/exe")
|
||||
.argument(PRIVATE_ROLE_ARGUMENT)
|
||||
.argument(PRIVATE_RUNTIME_ROLE)
|
||||
.argument("--domain")
|
||||
.argument(hex(ownership.domain_id.as_bytes()))
|
||||
.argument("--generation")
|
||||
|
|
@ -459,7 +459,7 @@ impl RuntimeSupervisorLaunch {
|
|||
TargetCommand::new("/usr/bin/false").with_lifetime_pipe_parent_edge(),
|
||||
);
|
||||
launch.target = TargetCommand::new(runtime_supervisor_executable)
|
||||
.argument(PRIVATE_ROLE_ARGUMENT)
|
||||
.argument(PRIVATE_RUNTIME_ROLE)
|
||||
.argument("--domain")
|
||||
.argument(hex(ownership.domain_id.as_bytes()))
|
||||
.argument("--generation")
|
||||
|
|
@ -505,7 +505,7 @@ impl RuntimeSupervisorLaunch {
|
|||
|
||||
fn rebuild_target(&mut self) {
|
||||
let mut target = TargetCommand::new("/proc/self/exe")
|
||||
.argument(PRIVATE_ROLE_ARGUMENT)
|
||||
.argument(PRIVATE_RUNTIME_ROLE)
|
||||
.argument("--domain")
|
||||
.argument(hex(self.ownership.domain_id.as_bytes()))
|
||||
.argument("--generation")
|
||||
|
|
@ -658,7 +658,7 @@ impl RuntimeSupervisorLaunch {
|
|||
pub fn dispatch_private_runtime_role(arguments: &[OsString]) -> Option<io::Result<()>> {
|
||||
if arguments
|
||||
.first()
|
||||
.is_none_or(|argument| argument != PRIVATE_ROLE_ARGUMENT)
|
||||
.is_none_or(|argument| argument != PRIVATE_RUNTIME_ROLE)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue