summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2020-02-12 21:23:58 +0100
committerrabite <rabite@posteo.de>2020-02-12 21:26:39 +0100
commit02e767cf5079aa9f96ec71a6fb9995603a5a95e5 (patch)
tree126e9923800feb34d04c9946b0a0fb6ebd356b50
parentb3f1452a59030c483e08dc1ca9f6d91562a6f87b (diff)
switch to nix for killing preview subprocess
-rw-r--r--src/fail.rs11
-rw-r--r--src/preview.rs16
2 files changed, 18 insertions, 9 deletions
diff --git a/src/fail.rs b/src/fail.rs
index 0f05455..cf5acab 100644
--- a/src/fail.rs
+++ b/src/fail.rs
@@ -105,7 +105,9 @@ pub enum HError {
#[fail(display = "FileBrowser needs to know about all tab's files to run exec!")]
FileBrowserNeedTabFiles,
#[fail(display = "{}", _0)]
- FileError(crate::files::FileError)
+ FileError(crate::files::FileError),
+ #[fail(display = "{}", _0)]
+ Nix(#[cause] nix::Error)
}
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 {
fn from(error: std::char::ParseCharError) -> Self {
let err = HError::ParseCharError(error);
diff --git a/src/preview.rs b/src/preview.rs
index 3356e67..1770ac4 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -27,16 +27,16 @@ fn kill_proc() -> HResult<()> {
pid.map(|pid|
// Do this in another thread so we can wait on process to exit with SIGHUP
std::thread::spawn(move || {
+ use nix::{unistd::Pid,
+ sys::signal::{killpg, Signal}};
+
let sleep_time = std::time::Duration::from_millis(50);
- // Here be dragons
- unsafe {
- // Kill using process group, to clean up all child processes, too
- // 15 = SIGTERM, 9 = SIGKILL
- libc::killpg(pid as i32, 15);
- std::thread::sleep(sleep_time);
- libc::killpg(pid as i32, 9);
- }
+ // Kill using process group, to clean up all child processes, too
+ let pid = Pid::from_raw(pid as i32);
+ killpg(pid, Signal::SIGTERM).log();
+ std::thread::sleep(sleep_time);
+ killpg(pid, Signal::SIGKILL).log();
})
);
*pid = None;