use ::descriptor::DescriptorError;
use std::error::Error;
use std::fmt;
use super::pty::{MasterError, SlaveError};
pub type Result<T> = ::std::result::Result<T, ForkError>;
#[derive(Clone, Copy, Debug)]
pub enum ForkError {
Failure,
SetsidFail,
WaitpidFail,
IsChild,
IsParent,
BadMaster(MasterError),
BadSlave(SlaveError),
BadDescriptorMaster(DescriptorError),
BadDescriptorSlave(DescriptorError),
}
impl fmt::Display for ForkError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", ::errno::errno())
}
}
impl Error for ForkError {
fn description(&self) -> &str {
match *self {
ForkError::Failure => {
"On failure, -1 is returned in the parent,no child process is created, and errno \
isset appropriately."
}
ForkError::SetsidFail => {
"fails if the calling process is alreadya process group leader."
}
ForkError::WaitpidFail => "Can't suspending the calling process.",
ForkError::IsChild => "is child and not parent",
ForkError::IsParent => "is parent and not child",
ForkError::BadMaster(_) => "the master as occured an error",
ForkError::BadSlave(_) => "the slave as occured an error",
ForkError::BadDescriptorMaster(_) => "the master's descriptor as occured an error",
ForkError::BadDescriptorSlave(_) => "the slave's descriptor as occured an error",
}
}
fn cause(&self) -> Option<&Error> {
match *self {
ForkError::BadMaster(ref err) => Some(err),
ForkError::BadSlave(ref err) => Some(err),
ForkError::BadDescriptorMaster(ref err) => Some(err),
ForkError::BadDescriptorSlave(ref err) => Some(err),
_ => None,
}
}
}