added custom result type
This commit is contained in:
parent
23f5761d05
commit
f2c9dddb67
@ -2,6 +2,8 @@ use std::io;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("{msg}: {src}")]
|
||||
|
@ -6,7 +6,7 @@ mod spawner;
|
||||
mod specification;
|
||||
mod void;
|
||||
|
||||
use error::Error;
|
||||
use error::{Error, Result};
|
||||
use spawner::Spawner;
|
||||
use specification::Specification;
|
||||
|
||||
@ -18,7 +18,7 @@ use clap::{App, AppSettings};
|
||||
use nix::fcntl::OFlag;
|
||||
use nix::unistd::{self};
|
||||
|
||||
pub fn run() -> Result<(), Error> {
|
||||
pub fn run() -> Result<()> {
|
||||
// process arguments
|
||||
let matches = App::new("clone-shim")
|
||||
.version(env!("GIT_HASH"))
|
||||
@ -98,7 +98,7 @@ impl PipePair {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_pipes(names: Vec<&str>) -> Result<HashMap<String, PipePair>, Error> {
|
||||
fn create_pipes(names: Vec<&str>) -> Result<HashMap<String, PipePair>> {
|
||||
let mut pipes = HashMap::new();
|
||||
|
||||
for pipe in names {
|
||||
|
@ -3,7 +3,7 @@ use log::{debug, error, info};
|
||||
use super::specification::{Arg, Entrypoint, Pipe, Specification, Trigger};
|
||||
use super::PipePair;
|
||||
use crate::void::VoidBuilder;
|
||||
use crate::Error;
|
||||
use crate::{Error, Result};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::CString;
|
||||
@ -24,7 +24,7 @@ pub struct Spawner<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Spawner<'a> {
|
||||
pub fn spawn(&mut self) -> Result<(), Error> {
|
||||
pub fn spawn(&mut self) -> Result<()> {
|
||||
for (name, entrypoint) in &self.spec.entrypoints {
|
||||
info!("spawning entrypoint `{}`", name.as_str());
|
||||
|
||||
@ -79,7 +79,7 @@ impl<'a> Spawner<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pipe_trigger(&self, mut pipe: File, spec: &Entrypoint, name: &str) -> Result<(), Error> {
|
||||
fn pipe_trigger(&self, mut pipe: File, spec: &Entrypoint, name: &str) -> Result<()> {
|
||||
let mut buf = [0_u8; BUFFER_SIZE];
|
||||
|
||||
loop {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use log::debug;
|
||||
|
||||
use crate::Error;
|
||||
use crate::{Error, Result};
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
@ -115,7 +115,7 @@ impl Specification {
|
||||
(read, write)
|
||||
}
|
||||
|
||||
pub fn validate(&self) -> Result<(), Error> {
|
||||
pub fn validate(&self) -> Result<()> {
|
||||
// validate pipes match
|
||||
let (read, write) = self.pipes();
|
||||
let mut read_set = HashSet::with_capacity(read.len());
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::clone::{clone3, CloneArgs, CloneFlags};
|
||||
use crate::Error;
|
||||
use crate::{Error, Result};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
@ -29,7 +29,7 @@ impl VoidBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn spawn(&mut self, child_fn: impl FnOnce() -> i32) -> Result<VoidHandle, Error> {
|
||||
pub fn spawn(&mut self, child_fn: impl FnOnce() -> i32) -> Result<VoidHandle> {
|
||||
let mut args = CloneArgs::new(
|
||||
CloneFlags::CLONE_NEWCGROUP
|
||||
| CloneFlags::CLONE_NEWIPC
|
||||
@ -63,7 +63,7 @@ impl VoidBuilder {
|
||||
}
|
||||
|
||||
// per-namespace void creation
|
||||
fn newns_post(&self) -> Result<(), Error> {
|
||||
fn newns_post(&self) -> Result<()> {
|
||||
// consume the TempDir so it doesn't get deleted
|
||||
let new_root = tempfile::tempdir()?.into_path();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user