2021-07-29 20:18:22 +03:00
|
|
|
use crate::convert::{TryFrom, TryInto};
|
|
|
|
|
use crate::fmt;
|
|
|
|
|
use crate::io;
|
|
|
|
|
use crate::io::ErrorKind;
|
|
|
|
|
use crate::num::NonZeroI32;
|
|
|
|
|
use crate::sys;
|
|
|
|
|
use crate::sys::cvt;
|
|
|
|
|
use crate::sys::pipe::AnonPipe;
|
|
|
|
|
use crate::sys::process::process_common::*;
|
|
|
|
|
use crate::sys::unix::unsupported::*;
|
2022-03-01 14:46:41 -08:00
|
|
|
use core::ffi::NonZero_c_int;
|
2021-07-29 20:18:22 +03:00
|
|
|
|
|
|
|
|
use libc::{c_int, pid_t};
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Command
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
impl Command {
|
|
|
|
|
pub fn spawn(
|
|
|
|
|
&mut self,
|
|
|
|
|
default: Stdio,
|
|
|
|
|
needs_stdin: bool,
|
|
|
|
|
) -> io::Result<(Process, StdioPipes)> {
|
|
|
|
|
unsupported()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn exec(&mut self, default: Stdio) -> io::Error {
|
|
|
|
|
unsupported_err()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Processes
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
pub struct Process {
|
|
|
|
|
handle: pid_t,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Process {
|
|
|
|
|
pub fn id(&self) -> u32 {
|
|
|
|
|
0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn kill(&mut self) -> io::Result<()> {
|
|
|
|
|
unsupported()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn wait(&mut self) -> io::Result<ExitStatus> {
|
|
|
|
|
unsupported()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
|
|
|
|
|
unsupported()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
|
|
|
|
pub struct ExitStatus(c_int);
|
|
|
|
|
|
|
|
|
|
impl ExitStatus {
|
|
|
|
|
pub fn success(&self) -> bool {
|
|
|
|
|
self.code() == Some(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
|
|
|
|
|
Err(ExitStatusError(1.try_into().unwrap()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn code(&self) -> Option<i32> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn signal(&self) -> Option<i32> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn core_dumped(&self) -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn stopped_signal(&self) -> Option<i32> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn continued(&self) -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn into_raw(&self) -> c_int {
|
|
|
|
|
0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying.
|
|
|
|
|
impl From<c_int> for ExitStatus {
|
|
|
|
|
fn from(a: c_int) -> ExitStatus {
|
|
|
|
|
ExitStatus(a as i32)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for ExitStatus {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
write!(f, "exit code: {}", self.0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
|
|
|
|
pub struct ExitStatusError(NonZero_c_int);
|
|
|
|
|
|
|
|
|
|
impl Into<ExitStatus> for ExitStatusError {
|
|
|
|
|
fn into(self) -> ExitStatus {
|
|
|
|
|
ExitStatus(self.0.into())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ExitStatusError {
|
|
|
|
|
pub fn code(self) -> Option<NonZeroI32> {
|
|
|
|
|
ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|