1 use crate::std::fmt; 2 use crate::std::io; 3 use crate::std::num::NonZeroI32; 4 use crate::std::sys::process::process_common::*; 5 use crate::std::sys::unix::unsupported::*; 6 use core::ffi::NonZero_c_int; 7 use dlibc; 8 9 use dlibc::{c_int, pid_t}; 10 11 //////////////////////////////////////////////////////////////////////////////// 12 // Command 13 //////////////////////////////////////////////////////////////////////////////// 14 15 impl Command { spawn( &mut self, _default: Stdio, _needs_stdin: bool, ) -> io::Result<(Process, StdioPipes)>16 pub fn spawn( 17 &mut self, 18 _default: Stdio, 19 _needs_stdin: bool, 20 ) -> io::Result<(Process, StdioPipes)> { 21 unsupported() 22 } 23 output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)>24 pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> { 25 unsupported() 26 } 27 exec(&mut self, _default: Stdio) -> io::Error28 pub fn exec(&mut self, _default: Stdio) -> io::Error { 29 unsupported_err() 30 } 31 } 32 33 //////////////////////////////////////////////////////////////////////////////// 34 // Processes 35 //////////////////////////////////////////////////////////////////////////////// 36 37 pub struct Process { 38 _handle: pid_t, 39 } 40 41 impl Process { id(&self) -> u3242 pub fn id(&self) -> u32 { 43 0 44 } 45 kill(&mut self) -> io::Result<()>46 pub fn kill(&mut self) -> io::Result<()> { 47 unsupported() 48 } 49 wait(&mut self) -> io::Result<ExitStatus>50 pub fn wait(&mut self) -> io::Result<ExitStatus> { 51 unsupported() 52 } 53 try_wait(&mut self) -> io::Result<Option<ExitStatus>>54 pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> { 55 unsupported() 56 } 57 } 58 59 #[derive(PartialEq, Eq, Clone, Copy, Debug, Default)] 60 pub struct ExitStatus(c_int); 61 62 impl ExitStatus { 63 #[cfg_attr(target_os = "horizon", allow(unused))] success(&self) -> bool64 pub fn success(&self) -> bool { 65 self.code() == Some(0) 66 } 67 exit_ok(&self) -> Result<(), ExitStatusError>68 pub fn exit_ok(&self) -> Result<(), ExitStatusError> { 69 Err(ExitStatusError(1.try_into().unwrap())) 70 } 71 code(&self) -> Option<i32>72 pub fn code(&self) -> Option<i32> { 73 None 74 } 75 signal(&self) -> Option<i32>76 pub fn signal(&self) -> Option<i32> { 77 None 78 } 79 core_dumped(&self) -> bool80 pub fn core_dumped(&self) -> bool { 81 false 82 } 83 stopped_signal(&self) -> Option<i32>84 pub fn stopped_signal(&self) -> Option<i32> { 85 None 86 } 87 continued(&self) -> bool88 pub fn continued(&self) -> bool { 89 false 90 } 91 into_raw(&self) -> c_int92 pub fn into_raw(&self) -> c_int { 93 0 94 } 95 } 96 97 /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying. 98 impl From<c_int> for ExitStatus { from(a: c_int) -> ExitStatus99 fn from(a: c_int) -> ExitStatus { 100 ExitStatus(a as i32) 101 } 102 } 103 104 impl fmt::Display for ExitStatus { fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result105 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 106 write!(f, "exit code: {}", self.0) 107 } 108 } 109 110 #[derive(PartialEq, Eq, Clone, Copy, Debug)] 111 pub struct ExitStatusError(NonZero_c_int); 112 113 impl Into<ExitStatus> for ExitStatusError { into(self) -> ExitStatus114 fn into(self) -> ExitStatus { 115 ExitStatus(self.0.into()) 116 } 117 } 118 119 impl ExitStatusError { code(self) -> Option<NonZeroI32>120 pub fn code(self) -> Option<NonZeroI32> { 121 ExitStatus(self.0.into()) 122 .code() 123 .map(|st| st.try_into().unwrap()) 124 } 125 } 126