alnyan/yggdrasil: add ExitStatusExt

This commit is contained in:
2024-01-15 18:24:37 +02:00
parent ac9607f8fb
commit 3f70d2eb96
2 changed files with 27 additions and 4 deletions
+16 -3
View File
@@ -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<F: Into<RawFd>>(&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<Signal>;
}
#[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<Signal> {
self.as_inner().signal()
}
}
+11 -1
View File
@@ -150,7 +150,17 @@ impl ExitStatus {
}
pub fn code(&self) -> Option<i32> {
Some(i32::from(self.0))
match self.0 {
OsExitCode::Exited(code) => Some(code),
_ => None,
}
}
pub fn signal(&self) -> Option<OsSignal> {
match self.0 {
OsExitCode::BySignal(sig) => Some(sig),
_ => None,
}
}
}