-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into clippy
- Loading branch information
Showing
6 changed files
with
233 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::os::unix::process::{CommandExt, ExitStatusExt}; | ||
use std::process::{Child, Command, ExitStatus}; | ||
|
||
use anyhow::bail; | ||
use nix::errno::Errno; | ||
use nix::sys::signal::{killpg, Signal}; | ||
use nix::unistd::Pid; | ||
use tracing::warn; | ||
|
||
use crate::Result; | ||
|
||
use super::Exit; | ||
|
||
#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // To match Windows | ||
#[mutants::skip] // hard to exercise the ESRCH edge case | ||
pub(super) fn terminate_child(child: &mut Child) -> Result<()> { | ||
let pid = Pid::from_raw(child.id().try_into().unwrap()); | ||
match killpg(pid, Signal::SIGTERM) { | ||
Ok(()) => Ok(()), | ||
Err(Errno::ESRCH) => { | ||
Ok(()) // Probably already gone | ||
} | ||
Err(Errno::EPERM) if cfg!(target_os = "macos") => { | ||
Ok(()) // If the process no longer exists then macos can return EPERM (maybe?) | ||
} | ||
Err(errno) => { | ||
// TODO: Maybe strerror? | ||
let message = format!("failed to terminate child: error {errno}"); | ||
warn!("{}", message); | ||
bail!(message); | ||
} | ||
} | ||
} | ||
|
||
#[mutants::skip] | ||
pub(super) fn configure_command(command: &mut Command) { | ||
command.process_group(0); | ||
} | ||
|
||
impl From<ExitStatus> for Exit { | ||
fn from(status: ExitStatus) -> Self { | ||
if let Some(code) = status.code() { | ||
if code == 0 { | ||
Exit::Success | ||
} else { | ||
Exit::Failure(code) | ||
} | ||
} else if let Some(signal) = status.signal() { | ||
return Exit::Signalled(signal); | ||
} else { | ||
Exit::Other | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::process::{Child, Command, ExitStatus}; | ||
|
||
use anyhow::Context; | ||
|
||
use crate::Result; | ||
|
||
use super::Exit; | ||
|
||
#[mutants::skip] // hard to exercise the ESRCH edge case | ||
pub(super) fn terminate_child(child: &mut Child) -> Result<()> { | ||
child.kill().context("Kill child") | ||
} | ||
|
||
#[mutants::skip] | ||
pub(super) fn configure_command(_command: &mut Command) {} | ||
|
||
impl From<ExitStatus> for Exit { | ||
fn from(status: ExitStatus) -> Self { | ||
if let Some(code) = status.code() { | ||
if code == 0 { | ||
Exit::Success | ||
} else { | ||
Exit::Failure(code) | ||
} | ||
} else { | ||
Exit::Other | ||
} | ||
} | ||
} |
Oops, something went wrong.