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 program_path;
pub(crate) mod protocol;
#[cfg(target_os = "linux")]
pub(crate) mod run;
pub(crate) mod stderr;
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::sync::atomic::{AtomicBool, Ordering};
use protocol::ShimArgs;
static INSTALLED: AtomicBool = AtomicBool::new(false);
pub fn init() {
install(None);
}
pub fn installed() -> bool {
INSTALLED.load(Ordering::Relaxed)
}
#[doc(hidden)]
pub fn init_with_test_hooks(hooks: &'static dyn ShimTestHooks) {
install(Some(hooks));
}
fn install(hooks: Option<&'static dyn ShimTestHooks>) {
INSTALLED.store(true, Ordering::Relaxed);
let argv: Vec<_> = std::env::args_os().collect();
match ShimArgs::parse(&argv) {
Ok(None) => {}
Ok(Some(args)) => std::process::exit(run_shim(&args, hooks)),
Err(e) => {
stderr::line(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 {
stderr::line(format_args!(
"this platform has no shim; the program was not started (exit {})",
codes::INVOCATION
));
codes::INVOCATION
}
#[cfg(test)]
#[path = "shim/init_tests.rs"]
mod init_tests;