summaryrefslogtreecommitdiff
path: root/runtime/ops/spawn.rs
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2022-05-18 07:32:45 +0200
committerGitHub <noreply@github.com>2022-05-18 07:32:45 +0200
commita151092aa144054c0d088843e306e51430ad4bba (patch)
tree7c73c6f914929a0e7e1d961d7453462103ee506a /runtime/ops/spawn.rs
parent9a85a95c435968e5bdf6e71192be3ed239fd2205 (diff)
feat: return a signal string instead number on ChildStatus (#14643)
Diffstat (limited to 'runtime/ops/spawn.rs')
-rw-r--r--runtime/ops/spawn.rs41
1 files changed, 24 insertions, 17 deletions
diff --git a/runtime/ops/spawn.rs b/runtime/ops/spawn.rs
index 0f329e16e..7e7e2d05e 100644
--- a/runtime/ops/spawn.rs
+++ b/runtime/ops/spawn.rs
@@ -73,22 +73,29 @@ pub struct ChildStdio {
pub struct ChildStatus {
success: bool,
code: i32,
- signal: Option<i32>,
+ signal: Option<String>,
}
-impl From<std::process::ExitStatus> for ChildStatus {
- fn from(status: ExitStatus) -> Self {
+impl TryFrom<std::process::ExitStatus> for ChildStatus {
+ type Error = AnyError;
+
+ fn try_from(status: ExitStatus) -> Result<Self, Self::Error> {
let code = status.code();
#[cfg(unix)]
let signal = status.signal();
#[cfg(not(unix))]
- let signal = None;
+ let signal: Option<i32> = None;
- if let Some(signal) = signal {
+ let status = if let Some(signal) = signal {
ChildStatus {
success: false,
code: 128 + signal,
- signal: Some(signal),
+ #[cfg(unix)]
+ signal: Some(
+ crate::ops::signal::signal_int_to_str(signal)?.to_string(),
+ ),
+ #[cfg(not(unix))]
+ signal: None,
}
} else {
let code = code.expect("Should have either an exit code or a signal.");
@@ -98,7 +105,9 @@ impl From<std::process::ExitStatus> for ChildStatus {
code,
signal: None,
}
- }
+ };
+
+ Ok(status)
}
}
@@ -219,15 +228,13 @@ async fn op_spawn_wait(
.borrow_mut()
.resource_table
.take::<ChildResource>(rid)?;
- Ok(
- Rc::try_unwrap(resource)
- .ok()
- .unwrap()
- .0
- .wait()
- .await?
- .into(),
- )
+ Rc::try_unwrap(resource)
+ .ok()
+ .unwrap()
+ .0
+ .wait()
+ .await?
+ .try_into()
}
#[op]
@@ -240,7 +247,7 @@ fn op_spawn_sync(
let output = create_command(state, args)?.output()?;
Ok(SpawnOutput {
- status: output.status.into(),
+ status: output.status.try_into()?,
stdout: if stdout {
Some(output.stdout.into())
} else {