boringtun icon indicating copy to clipboard operation
boringtun copied to clipboard

Can't intercept SIGINT, SIGTERM when using boringtun

Open rrebelo62 opened this issue 2 years ago • 2 comments

Boringtun intercepts SIGINT and SIGTERM on register_api_signal_handlers(), at device/api.rs (line 144).

Therefore, any application that wants to handle these signals will be unable to do so.

Just as boringtun needs to do some cleanup on that case, an application might have some of it's cleaning to do or being able to decide to keep on running or not depending on the different reasons boringtun has stopped (e.g: distinguish network error from ctrl-c).

I suggest 2 different approaches to solving this:

  1. Through dependency injection: the api could allow to add a callback / lambda to be called if the user presses ctrl-c or another cause for boringtun exit happens

  2. Through a return value: currently DeviceHandler::wait() doesn't return any value. It could return a value describing the reason it stopped.

rrebelo62 avatar Jan 19 '23 02:01 rrebelo62

Funny, I was about to post an issue about this behavior yesterday as well but didn't get the chance. I have a project with boringtun as a dependency, and in 'release' mode (but not 'debug' mode), my binary cannot be killed with Ctrl-C, just nothing at all happens. It would be nice to see a way for both my code and boringtun to be able to clean up properly on Ctrl-C.

ngc0202 avatar Jan 19 '23 13:01 ngc0202

I've been meaning to rewrite much of this crate for a while, and this is probably something best handled then.

Noah-Kennedy avatar Jan 20 '23 23:01 Noah-Kennedy