Skip to main content

open_envault/
runtime.rs

1use anyhow::bail;
2use std::{
3    collections::BTreeMap,
4    process::{Command, Stdio},
5};
6pub fn exec(command: &[String], values: &BTreeMap<String, String>) -> anyhow::Result<i32> {
7    let Some(program) = command.first() else {
8        bail!("a child command is required after --")
9    };
10    let status = Command::new(program)
11        .args(&command[1..])
12        .envs(values)
13        .stdin(Stdio::inherit())
14        .stdout(Stdio::inherit())
15        .stderr(Stdio::inherit())
16        .status()?;
17    Ok(status.code().unwrap_or(128 + status.signal().unwrap_or(0)))
18}
19trait SignalCode {
20    fn signal(&self) -> Option<i32>;
21}
22impl SignalCode for std::process::ExitStatus {
23    fn signal(&self) -> Option<i32> {
24        #[cfg(unix)]
25        {
26            std::os::unix::process::ExitStatusExt::signal(self)
27        }
28        #[cfg(not(unix))]
29        {
30            None
31        }
32    }
33}