From 3f70d2eb96cc04eed5e093a88f8708b2ed0a5720 Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Mon, 15 Jan 2024 18:24:37 +0200 Subject: [PATCH] alnyan/yggdrasil: add ExitStatusExt --- library/std/src/os/yggdrasil/process.rs | 19 ++++++++++++++++--- library/std/src/sys/yggdrasil/process.rs | 12 +++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/library/std/src/os/yggdrasil/process.rs b/library/std/src/os/yggdrasil/process.rs index b69d884c0aa..f7b9804d2a8 100644 --- a/library/std/src/os/yggdrasil/process.rs +++ b/library/std/src/os/yggdrasil/process.rs @@ -1,9 +1,9 @@ #![stable(feature = "os", since = "1.0.0")] -use crate::process::Command; +use crate::process::{Command, ExitStatus}; use crate::sealed::Sealed; -use crate::sys_common::AsInnerMut; -use yggdrasil_rt::io::RawFd; +use crate::sys_common::{AsInner, AsInnerMut}; +use yggdrasil_rt::{io::RawFd, process::Signal}; #[unstable(feature = "yggdrasil_os", issue = "none")] pub trait CommandExt: Sealed { @@ -14,6 +14,12 @@ pub trait CommandExt: Sealed { unsafe fn gain_terminal>(&mut self, fd: F) -> &mut Command; } +#[unstable(feature = "yggdrasil_os", issue = "none")] +pub trait ExitStatusExt: Sealed { + #[unstable(feature = "yggdrasil_os", issue = "none")] + fn signal(&self) -> Option; +} + #[unstable(feature = "yggdrasil_os", issue = "none")] impl CommandExt for Command { fn process_group(&mut self, pgroup: u32) -> &mut Command { @@ -26,3 +32,10 @@ impl CommandExt for Command { self } } + +#[unstable(feature = "yggdrasil_os", issue = "none")] +impl ExitStatusExt for ExitStatus { + fn signal(&self) -> Option { + self.as_inner().signal() + } +} diff --git a/library/std/src/sys/yggdrasil/process.rs b/library/std/src/sys/yggdrasil/process.rs index 8294bb6ebbd..6a0f054a9f5 100644 --- a/library/std/src/sys/yggdrasil/process.rs +++ b/library/std/src/sys/yggdrasil/process.rs @@ -150,7 +150,17 @@ impl ExitStatus { } pub fn code(&self) -> Option { - Some(i32::from(self.0)) + match self.0 { + OsExitCode::Exited(code) => Some(code), + _ => None, + } + } + + pub fn signal(&self) -> Option { + match self.0 { + OsExitCode::BySignal(sig) => Some(sig), + _ => None, + } } }