Bump nix and ctrlc crate to resolve audit failures (#20558)

* Bump nix and ctrlc

* Update to direct error variants

* Use statement cleanup
This commit is contained in:
Tyera Eulberg
2021-10-08 17:18:33 -06:00
committed by GitHub
parent 0545306f0c
commit 78f9e65f30
9 changed files with 35 additions and 29 deletions

View File

@ -16,11 +16,11 @@ bzip2 = "0.4.3"
chrono = { version = "0.4.11", features = ["serde"] }
clap = { version = "2.33.1" }
console = "0.14.1"
ctrlc = { version = "3.1.9", features = ["termination"] }
ctrlc = { version = "3.2.1", features = ["termination"] }
dirs-next = "2.0.0"
indicatif = "0.16.2"
lazy_static = "1.4.0"
nix = "0.20.0"
nix = "0.23.0"
reqwest = { version = "0.11.5", default-features = false, features = ["blocking", "rustls-tls", "json"] }
serde = { version = "1.0.130", features = ["derive"] }
serde_yaml = "0.8.21"

View File

@ -1,5 +1,4 @@
use std::io;
use std::process::Child;
use std::{io, process::Child};
fn kill_process(process: &mut Child) -> Result<(), io::Error> {
if let Ok(()) = process.kill() {
@ -17,13 +16,18 @@ pub fn stop_process(process: &mut Child) -> Result<(), io::Error> {
#[cfg(not(windows))]
pub fn stop_process(process: &mut Child) -> Result<(), io::Error> {
use nix::errno::Errno::{EINVAL, EPERM, ESRCH};
use nix::sys::signal::{kill, Signal};
use nix::unistd::Pid;
use nix::Error::Sys;
use std::io::ErrorKind;
use std::thread;
use std::time::{Duration, Instant};
use {
nix::{
errno::Errno::{EINVAL, EPERM, ESRCH},
sys::signal::{kill, Signal},
unistd::Pid,
},
std::{
io::ErrorKind,
thread,
time::{Duration, Instant},
},
};
let nice_wait = Duration::from_secs(5);
let pid = Pid::from_raw(process.id() as i32);
@ -40,17 +44,17 @@ pub fn stop_process(process: &mut Child) -> Result<(), io::Error> {
kill_process(process)?;
}
}
Err(Sys(EINVAL)) => {
Err(EINVAL) => {
println!("Invalid signal. Killing process {}", pid);
kill_process(process)?;
}
Err(Sys(EPERM)) => {
Err(EPERM) => {
return Err(io::Error::new(
ErrorKind::InvalidInput,
format!("Insufficient permissions to signal process {}", pid),
));
}
Err(Sys(ESRCH)) => {
Err(ESRCH) => {
return Err(io::Error::new(
ErrorKind::InvalidInput,
format!("Process {} does not exist", pid),