mirror of https://github.com/bobwen-dev/hunter
switch to nix for killing preview subprocess
This commit is contained in:
parent
b3f1452a59
commit
02e767cf50
11
src/fail.rs
11
src/fail.rs
|
@ -105,7 +105,9 @@ pub enum HError {
|
||||||
#[fail(display = "FileBrowser needs to know about all tab's files to run exec!")]
|
#[fail(display = "FileBrowser needs to know about all tab's files to run exec!")]
|
||||||
FileBrowserNeedTabFiles,
|
FileBrowserNeedTabFiles,
|
||||||
#[fail(display = "{}", _0)]
|
#[fail(display = "{}", _0)]
|
||||||
FileError(crate::files::FileError)
|
FileError(crate::files::FileError),
|
||||||
|
#[fail(display = "{}", _0)]
|
||||||
|
Nix(#[cause] nix::Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HError {
|
impl HError {
|
||||||
|
@ -367,6 +369,13 @@ impl From<std::num::ParseIntError> for HError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<nix::Error> for HError {
|
||||||
|
fn from(error: nix::Error) -> Self {
|
||||||
|
let err = HError::Nix(error);
|
||||||
|
err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<std::char::ParseCharError> for HError {
|
impl From<std::char::ParseCharError> for HError {
|
||||||
fn from(error: std::char::ParseCharError) -> Self {
|
fn from(error: std::char::ParseCharError) -> Self {
|
||||||
let err = HError::ParseCharError(error);
|
let err = HError::ParseCharError(error);
|
||||||
|
|
|
@ -27,16 +27,16 @@ fn kill_proc() -> HResult<()> {
|
||||||
pid.map(|pid|
|
pid.map(|pid|
|
||||||
// Do this in another thread so we can wait on process to exit with SIGHUP
|
// Do this in another thread so we can wait on process to exit with SIGHUP
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
|
use nix::{unistd::Pid,
|
||||||
|
sys::signal::{killpg, Signal}};
|
||||||
|
|
||||||
let sleep_time = std::time::Duration::from_millis(50);
|
let sleep_time = std::time::Duration::from_millis(50);
|
||||||
|
|
||||||
// Here be dragons
|
// Kill using process group, to clean up all child processes, too
|
||||||
unsafe {
|
let pid = Pid::from_raw(pid as i32);
|
||||||
// Kill using process group, to clean up all child processes, too
|
killpg(pid, Signal::SIGTERM).log();
|
||||||
// 15 = SIGTERM, 9 = SIGKILL
|
std::thread::sleep(sleep_time);
|
||||||
libc::killpg(pid as i32, 15);
|
killpg(pid, Signal::SIGKILL).log();
|
||||||
std::thread::sleep(sleep_time);
|
|
||||||
libc::killpg(pid as i32, 9);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
*pid = None;
|
*pid = None;
|
||||||
|
|
Loading…
Reference in New Issue