Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suspend when running hx within git #1843

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ grep-searcher = "0.1.8"

# Remove once retain_mut lands in stable rust
retain_mut = "0.1.7"
nix = "0.23"

[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
Expand Down
17 changes: 12 additions & 5 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ use crossterm::{
tty::IsTty,
};
#[cfg(not(windows))]
use {
signal_hook::{consts::signal, low_level},
signal_hook_tokio::Signals,
};
use {signal_hook::consts::signal, signal_hook_tokio::Signals};
#[cfg(windows)]
type Signals = futures_util::stream::Empty<()>;

Expand Down Expand Up @@ -254,9 +251,19 @@ impl Application {
use helix_view::graphics::Rect;
match signal {
signal::SIGTSTP => {
use nix::{
sys::signal::{self, Signal},
unistd::Pid,
};
self.compositor.save_cursor();
self.restore_term().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that you didn't follow the signal-hook docs: you're supposed to call low_level::raise(SIGSTOP)?;, not emulate_default_handler: https://docs.rs/signal-hook/latest/signal_hook/#a-complex-signal-handling-with-a-background-thread

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, seems to be the same underlying call though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's the same thing.

low_level::emulate_default_handler(signal::SIGTSTP).unwrap();
// low_level::emulate_default_handler(signal::SIGSTSP) only
// send SIGSTOP to the current process but since we use
// multi-process tokio, at times like using helix within
// git suspend will not work since only the current process
// is suspended, so we had to send SIGSTOP signal to the
// whole process to make sure it is suspended correctly.
signal::kill(Pid::from_raw(0), Signal::SIGSTOP).unwrap();
Copy link
Contributor Author

@pickfire pickfire Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archseer I can change it to libc::kill if you want since nix is an extra new crate now (libc we already need it anyway) but we only use this one line, but using libc directly will need unsafe and might take up several lines.

}
signal::SIGCONT => {
self.claim_term().await.unwrap();
Expand Down