diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-01-31 19:18:20 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-01-31 19:18:20 +0100 |
commit | b9e28bd7990b597d707fb9a81880dc14accc9c41 (patch) | |
tree | fbb54d67bac841728450b62cd192095b9d3993b5 /src/util.rs | |
parent | 6eb0851420b358132dd8a72312b25a1f7efd02de (diff) | |
download | rebel-b9e28bd7990b597d707fb9a81880dc14accc9c41.tar rebel-b9e28bd7990b597d707fb9a81880dc14accc9c41.zip |
Unshare/subuid handling
Buildah is too slow for our usecase. Handle userns setup ourselves, so
we can call runc directly.
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..c18a263 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,45 @@ +use std::{ + io::{Error, ErrorKind, Result}, + process::ExitStatus, +}; + +use nix::sys::wait; + +pub trait ToIOResult<T> { + fn to_io_result(self) -> Result<T>; +} + +impl<T> ToIOResult<T> for nix::Result<T> { + fn to_io_result(self) -> Result<T> { + self.map_err(|error| Error::new(ErrorKind::Other, error)) + } +} + +pub trait Checkable { + fn check(&self) -> Result<()>; +} + +impl Checkable for ExitStatus { + fn check(&self) -> Result<()> { + if self.success() { + Ok(()) + } else { + Err(Error::new( + ErrorKind::Other, + format!("process exited with status {}", self), + )) + } + } +} + +impl Checkable for wait::WaitStatus { + fn check(&self) -> Result<()> { + match self { + wait::WaitStatus::Exited(_, 0) => Ok(()), + _ => Err(Error::new( + ErrorKind::Other, + format!("process exited with status {:?}", self), + )), + } + } +} |