mod choice;
pub(crate) mod codes;
#[cfg(target_os = "linux")]
pub(crate) mod creds;
#[cfg(test)]
pub(crate) mod fixtures;
pub(crate) mod fork_guard;
pub mod hooks;
pub(crate) mod link;
#[cfg(all(test, target_os = "linux"))]
pub(crate) mod owner_helper;
pub(crate) mod owner_watch;
pub(crate) mod private_dir;
pub(crate) mod protocol;
#[cfg(target_os = "linux")]
pub(crate) mod run;
pub(crate) mod step;
#[allow(unused_imports, reason = "nothing outside the tests of this module uses it")]
pub(crate) use choice::ShimChoice;
pub use hooks::{Gate, Inject, ShimTestHooks};
use std::ffi::OsString;
use protocol::ShimArgs;
pub(crate) fn run_if_invoked(argv: &[OsString], hooks: Option<&'static dyn ShimTestHooks>) {
match ShimArgs::parse(argv) {
Ok(None) => {}
Ok(Some(args)) => std::process::exit(run_shim(&args, hooks)),
Err(e) => {
crate::role::line(
crate::role::SHIM,
format_args!(
"{}; the program was not started (exit {})",
crate::error::Report(&e),
codes::INVOCATION
),
);
std::process::exit(codes::INVOCATION);
}
}
}
#[cfg(target_os = "linux")]
fn run_shim(args: &ShimArgs, hooks: Option<&'static dyn ShimTestHooks>) -> i32 {
run::run(args, hooks)
}
#[cfg(not(target_os = "linux"))]
fn run_shim(_: &ShimArgs, _: Option<&'static dyn ShimTestHooks>) -> i32 {
crate::role::line(
crate::role::SHIM,
format_args!(
"this platform has no shim; the program was not started (exit {})",
codes::INVOCATION
),
);
codes::INVOCATION
}