-
Notifications
You must be signed in to change notification settings - Fork 0
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
panic when piping into a bad process? #21
Comments
I've noticed this is a problem with more of my programs (like hedu). It is not the case in ripgrep for example. The panic is in writing of the std lib (since writing fails in that case of course, even something like |
This seems to be due to a design difference between rust and c programs. When a rust program receives a |
Based on this: I seem to have two ways: register a signal handler for SIGPIPE, or just ignore this. Seeing that I already have a signal_hook function that I use in the daemon, I might just do the same for all things. |
Tried this approach, but it does not work. fn signal_hook() {
unsafe {
signal::signal(Signal::SIGTERM, SigHandler::Handler(handle_signal))
.expect("failed to set up signal handler");
signal::signal(Signal::SIGPIPE, SigHandler::Handler(handle_signal))
.expect("failed to set up signal handler");
signal::signal(Signal::SIGINT, SigHandler::Handler(handle_signal))
.expect("failed to set up signal handler");
}
}
extern "C" fn handle_signal(signal: i32) {
let _signal: nix::sys::signal::Signal =
nix::sys::signal::Signal::try_from(signal).expect("got an undefined SIGNAL");
{
// the default behavior is terminating
std::process::exit(1);
}
} The logic would work out, but you can't exit the program in a signal handler or panic there either without causing deeper errors. the handler is a function that cannot be unwinded, so panicing does not work (not that it would actually do anything), and just using |
I don't really know what to do with this to make the unfriendly error go away. |
This seems to be the official issue for it in rust. I'm definitely not rewriting every print or checking some global variable from the signal handler for this. |
The text was updated successfully, but these errors were encountered: