pyc_shell/shell/proc/
mod.rs1extern crate nix;
27
28mod pipe;
29pub mod process;
30
31use std::path::PathBuf;
32use std::time::{Duration, Instant};
33
34use pipe::Pipe;
35
36#[derive(Copy, Clone, PartialEq, std::fmt::Debug)]
42pub enum ShellProcState {
43 Idle,
44 SubprocessRunning,
45 Terminated
46}
47
48#[derive(Copy, Clone, PartialEq, std::fmt::Debug)]
52pub enum ShellError {
53 CouldNotStartProcess,
54 InvalidData,
55 IoTimeout,
56 ShellRunning,
57 ShellTerminated,
58 CouldNotKill,
59 PipeError(nix::errno::Errno)
60}
61
62#[derive(std::fmt::Debug)]
66pub struct ShellProc {
67 pub state: ShellProcState, pub exit_status: u8, pub pid: i32, pub wrkdir: PathBuf, pub exec_time: Duration, rc: u8, uuid: String, start_time: Instant, stdout_cache: Option<String>, echo_command: String, stdin_pipe: Pipe,
80 stdout_pipe: Pipe,
81 stderr_pipe: Pipe
82}
83
84impl std::fmt::Display for ShellError {
85 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
86 let code_str: String = match self {
87 ShellError::CouldNotStartProcess => String::from("Could not start process"),
88 ShellError::InvalidData => String::from("Invalid data from process"),
89 ShellError::IoTimeout => String::from("I/O timeout"),
90 ShellError::ShellTerminated => String::from("Shell has terminated"),
91 ShellError::ShellRunning => String::from("Tried to clean shell up while still running"),
92 ShellError::CouldNotKill => String::from("Could not send signal to shell process"),
93 ShellError::PipeError(errno) => format!("Pipe error: {}", errno),
94 };
95 write!(f, "{}", code_str)
96 }
97}
98
99#[cfg(test)]
102mod tests {
103
104 use super::*;
105
106 #[test]
107 fn test_proc_fmt_shell_error() {
108 assert_eq!(format!("{}", ShellError::CouldNotStartProcess), String::from("Could not start process"));
109 assert_eq!(format!("{}", ShellError::InvalidData), String::from("Invalid data from process"));
110 assert_eq!(format!("{}", ShellError::IoTimeout), String::from("I/O timeout"));
111 assert_eq!(format!("{}", ShellError::ShellTerminated), String::from("Shell has terminated"));
112 assert_eq!(format!("{}", ShellError::ShellRunning), String::from("Tried to clean shell up while still running"));
113 assert_eq!(format!("{}", ShellError::CouldNotKill), String::from("Could not send signal to shell process"));
114 assert_eq!(format!("{}", ShellError::PipeError(nix::errno::Errno::EACCES)), format!("Pipe error: {}", nix::errno::Errno::EACCES));
115 }
116
117}