|
| 1 | +use crate::convert::TryInto; |
1 | 2 | use crate::io; |
| 3 | +use crate::fmt; |
2 | 4 | use crate::mem; |
3 | 5 | use crate::ptr; |
4 | 6 |
|
5 | 7 | use crate::sys::process::zircon::{Handle, zx_handle_t}; |
6 | 8 | use crate::sys::process::process_common::*; |
7 | 9 |
|
8 | | -use libc::size_t; |
| 10 | +use libc::{c_int, size_t}; |
9 | 11 |
|
10 | 12 | //////////////////////////////////////////////////////////////////////////////// |
11 | 13 | // Command |
@@ -160,7 +162,7 @@ impl Process { |
160 | 162 | return Err(io::Error::new(io::ErrorKind::InvalidData, |
161 | 163 | "Failed to get exit status of process")); |
162 | 164 | } |
163 | | - Ok(ExitStatus::new(proc_info.rec.return_code)) |
| 165 | + Ok(ExitStatus(proc_info.return_code)) |
164 | 166 | } |
165 | 167 |
|
166 | 168 | pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> { |
@@ -190,6 +192,36 @@ impl Process { |
190 | 192 | return Err(io::Error::new(io::ErrorKind::InvalidData, |
191 | 193 | "Failed to get exit status of process")); |
192 | 194 | } |
193 | | - Ok(Some(ExitStatus::new(proc_info.rec.return_code))) |
| 195 | + Ok(Some(ExitStatus(proc_info.return_code))) |
| 196 | + } |
| 197 | +} |
| 198 | + |
| 199 | +#[derive(PartialEq, Eq, Clone, Copy, Debug)] |
| 200 | +pub struct ExitStatus(i64); |
| 201 | + |
| 202 | +impl ExitStatus { |
| 203 | + pub fn success(&self) -> bool { |
| 204 | + self.code() == Some(0) |
| 205 | + } |
| 206 | + |
| 207 | + pub fn code(&self) -> Option<i32> { |
| 208 | + // FIXME: support extracting return code as an i64 |
| 209 | + self.0.try_into().ok() |
| 210 | + } |
| 211 | + |
| 212 | + pub fn signal(&self) -> Option<i32> { |
| 213 | + None |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | +impl From<c_int> for ExitStatus { |
| 218 | + fn from(a: c_int) -> ExitStatus { |
| 219 | + ExitStatus(a as i64) |
| 220 | + } |
| 221 | +} |
| 222 | + |
| 223 | +impl fmt::Display for ExitStatus { |
| 224 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 225 | + write!(f, "exit code: {}", self.0) |
194 | 226 | } |
195 | 227 | } |
0 commit comments