Skip to content

Commit

Permalink
helix-term: use libc directly to send STOP signal
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-h committed Dec 7, 2022
1 parent c730859 commit 3201342
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ grep-searcher = "0.1.10"

[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
nix = { version = "0.25.0", features = ["signal", "process"], default-features = false }
libc = "0.2.132"

[build-dependencies]
helix-loader = { version = "0.6", path = "../helix-loader" }
Expand Down
19 changes: 11 additions & 8 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,17 @@ impl Application {
.ok();
restore_term().unwrap();

// A pid of 0 sends the signal to the entire process group, allowing the user to
// regain control of their terminal if the editor was spawned under another process
// (e.g. when running `git commit`).
nix::sys::signal::kill(
nix::unistd::Pid::from_raw(0),
Some(nix::sys::signal::SIGSTOP),
)
.unwrap();
let res = unsafe {
// A pid of 0 sends the signal to the entire process group, allowing the user to
// regain control of their terminal if the editor was spawned under another process
// (e.g. when running `git commit`).
libc::kill(0, signal::SIGSTOP)
};

if res != 0 {
eprintln!("{}", std::io::Error::from_raw_os_error(res));
std::process::exit(res);
}
}
signal::SIGCONT => {
self.claim_term().await.unwrap();
Expand Down

0 comments on commit 3201342

Please sign in to comment.