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

Conversation

pickfire
Copy link
Contributor

@pickfire pickfire commented Mar 19, 2022

When editing git commit message using helix, when ctrl-z is pressed
the terminal will get stuck since helix does not suspend correctly,
as helix is currently using tokio with multi-threads, with signal-hook
default low_level::emulate_default_handler it only send the SIGSTOP to
the current process but tokio uses multi-process so not everything gets
suspended and the terminal also gets stuck.

Now switched to use libc kill function and send it to pid 0 so that all
processes gets suspended correctly.

Maybe I need to create an issue in signal-hook for this to check why they didn't kill all processes.

When editing git commit message using helix, when ctrl-z is pressed
the terminal will get stuck since helix does not suspend correctly,
as helix is currently using tokio with multi-threads, with signal-hook
default low_level::emulate_default_handler it only send the SIGSTOP to
the current process but tokio uses multi-process so not everything gets
suspended and the terminal also gets stuck.

Now switched to use libc kill function and send it to pid 0 so that all
processes gets suspended correctly.
// 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.

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.

@archseer
Copy link
Member

archseer commented May 2, 2022

Should fix this within signal-hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants