#![cfg_attr(feature = "docs", doc = include_str!("../README.md"))]
use std::{
fmt::{self, Debug, Display},
path::PathBuf,
process::{ExitStatus, Stdio},
sync::Arc,
};
#[cfg(feature = "async")]
pub use crate::asynchronous::*;
#[cfg(not(feature = "async"))]
pub use crate::synchronous::*;
#[cfg(feature = "async")]
pub mod asynchronous;
pub mod container;
pub mod error;
pub mod events;
#[cfg(not(feature = "async"))]
pub mod synchronous;
#[cfg(feature = "async")]
pub mod monitor;
pub mod options;
pub mod utils;
const JSON: &str = "json";
const TEXT: &str = "text";
pub type Result<T> = std::result::Result<T, crate::error::Error>;
#[derive(Debug, Clone)]
pub struct Response {
pub pid: u32,
pub status: ExitStatus,
pub output: String,
}
#[derive(Debug, Clone)]
pub struct Version {
pub runc_version: Option<String>,
pub spec_version: Option<String>,
pub commit: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub enum LogFormat {
Json,
#[default]
Text,
}
impl Display for LogFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LogFormat::Json => write!(f, "{}", JSON),
LogFormat::Text => write!(f, "{}", TEXT),
}
}
}
#[cfg(not(feature = "async"))]
pub type Command = std::process::Command;
#[cfg(feature = "async")]
pub type Command = tokio::process::Command;
#[derive(Debug, Clone)]
pub struct Runc {
command: PathBuf,
args: Vec<String>,
spawner: Arc<dyn Spawner + Send + Sync>,
}
impl Runc {
fn command(&self, args: &[String]) -> Result<Command> {
let args = [&self.args, args].concat();
let mut cmd = Command::new(&self.command);
cmd.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
cmd.args(&args).env_remove("NOTIFY_SOCKET");
Ok(cmd)
}
}