diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2019-09-24 21:34:44 -0700 |
|---|---|---|
| committer | Tyler Mandry <tmandry@gmail.com> | 2019-09-25 15:26:42 -0700 |
| commit | 80db06d6daa290fbc722fbae6dbfa0728ca259b5 (patch) | |
| tree | bdc280e1a17f02b1d55a30cde069f77cad466202 /src/libstd/sys/unix/process/process_fuchsia.rs | |
| parent | 6c2c29c43206d6e2f1091fa278d2792ea10e3659 (diff) | |
| download | rust-80db06d6daa290fbc722fbae6dbfa0728ca259b5.tar.gz rust-80db06d6daa290fbc722fbae6dbfa0728ca259b5.zip | |
Fix ExitStatus on Fuchsia
Fuchsia exit codes don't follow the convention of libc::WEXITSTATUS et al, and they are 64 bits instead of 32 bits. This gives Fuchsia its own representation of ExitStatus. Additionally, the zircon syscall structs were out of date, causing us to see bogus return codes.
Diffstat (limited to 'src/libstd/sys/unix/process/process_fuchsia.rs')
| -rw-r--r-- | src/libstd/sys/unix/process/process_fuchsia.rs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/libstd/sys/unix/process/process_fuchsia.rs b/src/libstd/sys/unix/process/process_fuchsia.rs index fff9fc6b3bb..2b1a3ecfd70 100644 --- a/src/libstd/sys/unix/process/process_fuchsia.rs +++ b/src/libstd/sys/unix/process/process_fuchsia.rs @@ -1,11 +1,13 @@ +use crate::convert::TryInto; use crate::io; +use crate::fmt; use crate::mem; use crate::ptr; use crate::sys::process::zircon::{Handle, zx_handle_t}; use crate::sys::process::process_common::*; -use libc::size_t; +use libc::{c_int, size_t}; //////////////////////////////////////////////////////////////////////////////// // Command @@ -160,7 +162,7 @@ impl Process { return Err(io::Error::new(io::ErrorKind::InvalidData, "Failed to get exit status of process")); } - Ok(ExitStatus::new(proc_info.rec.return_code)) + Ok(ExitStatus(proc_info.return_code)) } pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> { @@ -190,6 +192,36 @@ impl Process { return Err(io::Error::new(io::ErrorKind::InvalidData, "Failed to get exit status of process")); } - Ok(Some(ExitStatus::new(proc_info.rec.return_code))) + Ok(Some(ExitStatus(proc_info.return_code))) + } +} + +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub struct ExitStatus(i64); + +impl ExitStatus { + pub fn success(&self) -> bool { + self.code() == Some(0) + } + + pub fn code(&self) -> Option<i32> { + // FIXME: support extracting return code as an i64 + self.0.try_into().ok() + } + + pub fn signal(&self) -> Option<i32> { + None + } +} + +impl From<c_int> for ExitStatus { + fn from(a: c_int) -> ExitStatus { + ExitStatus(a as i64) + } +} + +impl fmt::Display for ExitStatus { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "exit code: {}", self.0) } } |
