1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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,
}
}
}